Algolia helper for Hugo

I’ve lurked here for a while, but this is my first actual post. I’ve recently started trying Algolia for for search on a new site, and hate anything manual about the upload process. So I whipped up a bare-bones uploader than can be called as part of an automated build.

It lives here:

It’s pretty simple - create your config file (or set the appropriate environment variables) and point it at a .json file. It will DELETE the contents of the index it’s pointed at and upload the new file in it’s place (because I hate the idea of deleted or modified content remaining in the search index). I’ve looked at implementing object IDs in my templates, and if I get that working I will probably update the tool to update instead of delete/upload (with optional wipe functionality for occasional housecleaning).

It’s written in golang, like Hugo. I haven’t put up any releases yet, but go get should get you a working binary. If anyone has a chance to use it, let me know how it works for you. PRs and feature requests are welcome, but my time to work on this is limited. I will strive to accept PRs as quickly as I can review them, but any feature requests will probably end up being a weekend code fest.

I hope to polish this up and get some actual releases on Github soon, but I want to get some usage feedback.


Thank you for sharing this! I will surely add it to my build script.

Some minor comments: I’m new to hugo and had to figure out I needed to run go build first, and it may be good for others.

But none the less, great work :grin:

Hopefully the need to go build will be gone very soon, if it’s there. go get should have downloaded the source and then ran a go install, providing you a binary in your $GOPATH/bin folder.

like I said @duckpuppy, I’m new to this so it may be a result of my lack of knowledge. :slight_smile:

Knock knock :slight_smile:

So I tried to implement this for my website index because the Algolia solution (atomic-algolia) stopped working a while ago magically. I get to the point where I have the binary produced and run the following line:

~/go/src/ -f public/algolia.json -c .env update

I receive an error:

[23:09:54][patrick@skadi] ~/Projects/Me/ (+1|%0|!6528|0)
❯ ~/go/src/ -f public/algolia.json -c .env update
   • Deleting existing objects
   ⨯ Failed to delete existing objects error=Cannot perform request [POST] /1/indexes//clear ( Post dial tcp: lookup no such host

Where do I start to debug?

  • .env has the configuration
    algolia_app_id: ***
    algolia_api_key: ***
    algolia_index_name: ***
  • I don’t think we come to the part where my algolia.json is read, so I leave that one out.
  • The command is run from within my site repository

That looks like the DNS for the server isn’t resolving. Have you tried with another network/computer?

Yes, but they come out of the same network in the end, so that probably won’t help to check resolving issues.

The other thing is: the subdomain is (that’s an invalid format) which points me more to an error in a function that retrieves that host we speak of. Maybe Algolia changed something in the way it returns a setup.

I tried renaming .env to .env.yaml to no change and will check deeper later. looks like he does not read my config.