So I wrote a new static-site generator
I used to generate this blog from Markdown files using a static-site generator that I wrote in Python. The resulting HTML files were then hosted on Cloudflare Pages.
Late last year, the Python codebase stopped running smoothly because of dependency issues. I don't remember changing my system or Python version, or adding or removing any of the affected libraries.
First, the Markdown parser I used went missing, so I had to reinstall it in a new virtual environment. Then the feed generator complained about a missing function argument. (Minor problems like these inevitably crop up.)
So I decided to rewrite the SSG behind this blog in Go.
The whole process was pleasant, and GitHub Copilot was very helpful. It suggested dependencies for parsing Markdown and generating RSS feeds—goldmark and gorilla/feeds—as well as often-useful code completions. A few of its solutions used deprecated function calls but were educational nonetheless.
When you program, you carry over old habits from other languages. Here are a few things I learned with nudges from Copilot:
- Go doesn't support string interpolation with variable names, and there is a whole discussion about why.
- Go doesn't support optional arguments in function signatures. Instead, you can use a variadic function or an options struct.
- I tried to import a struct from the
mainpackage into a child package. That was a dumb idea because “importing themainpackage directly can lead to circular dependencies, which are not allowed in Go.” Instead, I could “move theBlogSettingtype to a separate package, which can then be imported by both themainandtemplatepackages.”
