The following allows you to easily generate an Algolia index with Hugo consisting of whatever front matter metadata you like.
There are plugins that generate indexes using NPM packages or other tools. The issue is that they don't have any context to your site configuration or Hugo's internals, so they may miss pages or index pages that should not be indexed.
Using Hugo means your index has the full context of your site available when being generated.
To generate the index you create the index's layout at layouts/_default/list.algolia.json
.
In this file, we loop through all of the list page's children and generate valid json for each field we want in the index.
We then use the site.outputs
or page.outputs
options to have a list page generate an index.
Push changes to Algolia using their Node SDK: https://www.algolia.com/doc/api-reference/api-methods/add-objects/?language=javascript#add-objects-with-automatic-objectid-assignments