Fix: silly import in generate objectID #129
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish site to Cloudflare Pages | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: 'latest' | |
extended: true | |
- name: Build | |
run: hugo --minify | |
- name: Deploy to Cloudflare Pages | |
if: success() | |
uses: cloudflare/[email protected] | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: d73a30412652351305e3f89fd125f690 | |
projectName: blog | |
directory: public | |
branch: main | |
- name: Generate Index ID for Algolia | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require("fs") | |
let data = JSON.parse(fs.readFileSync("public/index.json", "utf8")) | |
data = data.map((item, index) => ({ | |
...item, | |
objectID: item.objectID || `${index}` | |
})) | |
fs.writeFileSync("public/index_with_objectID.json", JSON.stringify(data, null, 2)) | |
- uses: algolia/setup-algolia-cli@master | |
- name: Upload Algolia Index | |
run: algolia indices clear ${{ secrets.ALGOLIA_INDEX_NAME }} --confirm && algolia objects import ${{ secrets.ALGOLIA_INDEX_NAME }} --file public/index_with_objectID.json | |
env: | |
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APP_ID }} | |
ALGOLIA_ADMIN_API_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }} |