I decided to try once again to replace my own site generator with Hugo. If you read previous posts you’ll remember that I tried that a while back and found the task pretty daunting and ultimately not worth the benefits. But I had been using Hugo for several small projects, like my podcast site, my family site, my district Python PLC site, and my portfolio site… and after becoming more familiar with its features, and coming to appreciate how powerful of a system it is, I realized that, however big the investment might be in time, it would probably be worth it if I am able to integrate it with my project.

It has been quite a challenge, and I’m a little embarrassed to say what my biggest challenge was because it turned out to be something silly. I was having trouble mounting my user data files at ./internal/data/users. When I ran hugo through my app, which uses the simple command hugo it would build the pages using json generated by my app, but it wouldn’t add the files from ./internal/data/users. But when I ran hugo server it was adding them. ChatGPT kept telling me that this was a known quirky difference between hugo build and hugo server, and I was getting very frustrated trying to figure out how people get around this “known quirk”. Well it turns out I had simply forgot that I was running the app in a container where the file paths are different so the mount was only working when I ran hugo server locally and not in the container. I changed the paths to container paths, and it works fine. 🤦🏻‍♂️🤦🏻‍♂️🤦🏻‍♂️

But my second biggest challenge, which remains with me today, has been using go templates. My experience with this has been pretty awful to be quite honest. I have had a lot of trouble finding the right setup. I’m using the hugo prettier plugin which is alright and I’m not sure if there’s a better setup which is pretty sad. In order to keep autoformat from putting stuff on the same line e.g. {{range slice}} {{end}} I have to put an html comment between them, which prevents indentation but that’s something that apparently, that I just have to live with. Compared with using templ, this feels like stone-age technology. Aside from the bad auto-formatting, there’s no autocomplete or hover-over documentation which just makes this so much more painful. So I’m avoiding writing templates as much as possible.

UPDATE: right after writing this, I checked the docs again realized that I simply needed to add something right there in the docs for the plugin:

{
  "plugins": ["prettier-plugin-go-template"],
  "overrides": [
    {
      "files": ["*.html"],
      "options": {
        "parser": "go-template",
      },
    },
  ],
}

🤦🏻‍♂️🤦🏻‍♂️🤦🏻‍♂️ again! Better late than never, though! Now it’s quite pleasant. Not quite as nice as .templ but, not nearly as bad.

Side note, with Hugo in particular ChatGPT has been making a lot of stuff up. It’s sometimes helpful but other times it leads me astray. It does make me shudder a bit to think of how many things I may believe mistakenly because of something ChatGPT hallucinated.

But at this point in time I have reached a significant breakthrough where I’m fairly confident that using Hugo will be superior to my own site generator.