Rendering posts
Date: Wednesday, 30. of April 2025
Setting up a simple blog with golang templating
I recently used the polarsteps thing on a vacation to Paris. Well actually I'm on the way back from that. I kind of like the idea of writing down what happened on a vacation with pictures and all, but polarsteps kind of has the annoying clause that they get a license to any pictures uploaded. Also they do not provide a rss/atom feed for people wanting to subscribe. Not cool.
Well I have this website which I do pretty much nothing with, other than use it as a git host and a place to have my contact info here on the internet. Why not put it here (with some security maybe). Then I could also do an attempt at blogging (like thats going to happen, ever). I recently found this thing called DX-clusters which is really interesting, so it would be fun to write about that. Hopefully no one will actually read it.
So how to do a blog?? Well I could use some fancy cms, but a blog is basicly just a simple html file together with some RSS/Atom feed thing. Maybe a listing on the index.html would also be nice. In this post I will kind of explain my KISS solution to this "challenge". Pictures will be another thing, so at some point I will probably either write a new post or extend this one. Currently this will just serve to test that I can create text blogs.
Templating
I don't do many personal programming projects. And when I do they often get stuck before I am able to finish them. This is partly because I have a much too large scope, so I lose interest really quickly. But most often it is due to my inability to make choices. Like what language, stack, everything should I use.
Sometimes I want to try something new, like create something in Haskell, or ocaml. But I quickly notice the very lacking ecosystem of those languages, making it a nightmare to do even basic things. I have found that if I cannot find a good time library (preferably in stdlib) then I should start looking at some other language.
Rust is a very nice language and it has a nice time library, so many of my personal projects have used Rust. However, now I just get stuck selecting which library to use. I find this very hard in rust, because I need to figure out multiple different (rather complicated) libraries and how they fit together. While also fighting the rust typesystem, which I'm not super duper friends with yet.
Actually I have noticed that the projects I write in golang have the highest chances of success. The language itself is rather painful to write, but the massive stdlib means that all my decision problems have been solved before I even begin a project. Just do it the stdlib way, anything more advanced is probably not needed anyway.
So this page has been rendered with the okay'ish templating language included in golang. And not much else actually. Well I did do something kind of cursed.
Something kind of cursed
When rendering out a page, I can those to write
{{ linkpost "post/2025-04-08-rendering-posts.html" }}
which will render out the specific post in the served
directory, and return the path where the post can be accessed. That
means that I'm calling the templating library while rendering
templates. It seems to work just fine. I also added
a linkraw
for raw files.
Also while rendering a post, the engine is given a reference to a
metadata object, which the template can override. So the template
function title
will save that title in the metadata and
return the given title to be used in the document itself (inside a
h1 for example).
I think these hacks are okay, because the program is only run when i make changes to the git repo. And then the site is just build to a static set of files.
Generate Feeds
I have no idea of RSS and ATOM feeds work. But I do know that I want
them generated for this site. So I decided to use the gorilla feed
library. Here content is put in the format agnostic feed
struct, which can then be rendered to both rss and atom. Pretty nice.
I decided to render all the posts two times, one with and without header and footer. That way I could include the content in the feed itself. I don't really expect to use this blog, but if I do then I should probably limit the number of posts included in the feed. Well that is a problem for later :-).