Tips about algolia

Find out how to use algolia in the FixIt theme and update index automatically.
Create algolia Application
- Register algolia account
- Create an application in algolia, such as
fixit-blog - Select the application
fixit-blog=> ClickData Sources=> ClickIndices=> ClickCreate Index - Create an index, such as
index.en - Click
Settings=> ClickAPI Keys=> Copy and save API KeysApplication IDSearch-Only API KeyAdmin API Key(please do not disclose it)
Application ID and Search-Only API Key are used for search configuration, and Admin API Key is used to automatically update the index.
Algolia in FixIt
Based on the API Keys obtained in the previous step, to configure the algolia search feature, you need to add the following content to the site configuration.
| |
为了生成搜索功能所需要的 index.json, 请在你的站点配置中添加 JSON 输出文件类型到 outputs 部分的 home 字段中。
In order to generate index.json for searching, add JSON output file type to the home of the outputs part in your site configuration.
| |
Upload Index
Then, you need to upload index.json files to algolia to activate searching.
You could upload the index.json files by browsers but a CLI tool may be better.
Algolia Atomic is a good choice.
index.json for each language to the different index of algolia, such as zh-cn/index.json or fr/index.json…Preparation
Please make sure you have installed Node.js.
Algolia Atomic Installation
If there is no package.json file in your project, please create one first.
| |
Then install Algolia Atomic.
| |
Add the following content to the package.json file.
| |
Usage
After you execute the hugo command to generate the site, you can use the following command to upload the index.json file to algolia to update the index.
| |
- ALGOLIA_APP_ID: algolia Application ID
- ALGOLIA_ADMIN_KEY: algolia Admin API Key
- ALGOLIA_INDEX_NAME: algolia index name
- ALGOLIA_INDEX_FILE: local
index.jsonfile path
Automation
One more thing, you can automate the process of uploading index.json to algolia by using GitHub Actions
Add a
ALGOLIA_ADMIN_KEYsecret to your GitHub repository, the value is your algolia Admin API Key.Add a
.github/workflows/algolia-atomic.ymlfile to your GitHub repository, the content is as follows.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48name: Update Algolia Search Index on: push: branches: - master paths: - "content" workflow_dispatch: jobs: algolia-atomic: runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v4 with: submodules: recursive # Fetch Hugo themes (true OR recursive) fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - name: Setup Hugo uses: peaceiris/actions-hugo@v2 with: hugo-version: "latest" extended: true - name: Build run: | npm install npm run build - name: Update Algolia Index (en) env: ALGOLIA_APP_ID: YKOxxxxLUY # algolia Application ID ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }} # algolia Admin API Key ALGOLIA_INDEX_NAME: "index.en" # algolia index name ALGOLIA_INDEX_FILE: './public/index.json' # local index.json file path run: | npm run algolia - name: Update Algolia Index (zh-cn) env: ALGOLIA_APP_ID: YKOxxxxLUY ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }} ALGOLIA_INDEX_NAME: "index.zh-cn" ALGOLIA_INDEX_FILE: "./public/zh-cn/index.json" run: | npm run algoliaWhen you push your site to the
masterbranch of the GitHub repository, GitHub Actions will automatically execute thehugocommand to generate the site, and upload theindex.jsonto algolia.
🎉 Now, everything is ready!
Related Content
- Diagrams Support
- Extended Shortcodes Overview
- Extended Markdown Syntax
- PWA Support
- Extended Shortcode - typeit
