Static site generator written in Odin
this page is still incomplete and contains a number of typos and grammatical errors
I'm not a newbie to web development as I've been in the field of software for no less than 4 years but one issue has always plagued me since the day I wrote my first line of code and that is maintaining a personal website. I've always backed out not because it was too difficult but because it was a tedious ordeal, the tags, css, structuring and everything in-between would overwhelm and confuse me so much that I'd forget the reason I even started the website in the first place, Then suddenly I realised the problem.. It wasn't me, it was HTML! HTML was quite simply a language unsuitable for writing long pieces and blogs in because it gets cluttered quickly, hence the reason most people default to content management systems like wordpress or resort to writing dynamic websites where the content of the blog itself is served from a database.
I did not want to resort to any of these means, I wanted a lightweight website that made as little as zero api calls, one that loaded instantly and did not rely on a server for content. You might wonder why I didn't just have an LLM write the code if I found it so tedious, the reason was simple, even if the LLM could generate the html in an instant, I still needed to write the content of the blog somewhere and so that would still end up with me staring at an over-engineered website wondering whether to place my cursor in between the h2 tag or the div.
That was when I discovered Static site generators. Like the name implies, SSGs have only one core goal and that is to generate static html from content usually from Markdown. Markdown is perfect because it's easy to write, read and it ensures that you don't have to worry about styling and ui because it only provides the functionality needed to write, this makes it perfect for blogs, forums and documentation. Examples of SSGs include
And many more
The job of a Static site generator is simple, It takes in a simple language like markdown and outputs html, that's it! Of course, this is not all most SSGs do, they usually allow you (the user) to provide some sort of theme or template that the entire website will follow, the rules differ as some SSGs allow you to do this in a programming language, others use configuration files or even custom languages made specifically for this purpose, Let's see how my custom SSG Harp does it.
Harp is designed to be extremely simple and minimal, it does not provide any functionality that it does not have to,
although part of that can be attributed to the fact that it is currently in the early stages of developement.
When harp --build is run in a directory, Harp looks for a folder named "content" and if it exists, looks through all
the markdown files and begins translating them into their html equivalent. Before it does this, Harp looks for a "config.json"
file in the base path and checks for the variables defined in it, it then looks for a key named "template" and looks for the
name of the template assigned to it, this template is a file that may end in any extension, harp will search for this extension
inside the "templates" path. A template may look like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
</head>
<body>
{{content}}
</body>
</html>
Notice the {{}} inside the file? This is what makes the template a template. Harp will go through the template and anytime it
encounters one of those, it checks if the name inside the brackets matches any key inside of "config.json" and if it does, it
substitutes it for the value. It is important to note that the {{content}} key is built in and Harp will always substitute
it with the content of the corresponding markdown document.
Stuff built with Harp
That's all for now :)