How to build a blog the hard way?

14-04-2024

Why to blog in the first place?

I have been reading blogs since I started the 10th grade mainly for school work which at the time I hated and gave me an impression that no matter the content blogs were boring. In the last few months I started reading blogs related to programming and tech (mostly zig content) which nowadays I believe is the best way to learn programming.

So to answer the question, I like the golden rule.

That being said I needed to make the blog building fun and that's the reason for this title, so stick with me and I will explain "How to build a blog the hard way".

Template generator vs SSG

Confgen is a tool with the main purpose to generate config files. I use it for my humble dotfiles but that is a topic for another day.

There are many options for ssg(static site generators) like Hugo, Next.js... For some ssg, a single structural metadata file may correspond to an entire website with a framework like AngularJS. But the always evolving javascript frameworks can be a time consuming to keep up which then leads to more time spent in web dev than the kind of programming I like to do. With that being said, a ssg offers a more structured and scalable project in exchange of some flexibility but that is not how we build a blog the hard way. So lets talk a bit about the tool that will make things fun, shall we?

Confgen

Confgen is mainly written in Zig but all the configuration is in lua.

Anyone who has ever dealt with dotfiles knows how difficult it can be to customize them (for example when changing a theme) and that's where confgen comes into place.

So here we see 2 features of confgen. First, between <% and %> is where we set values to be written into the file and second, the opt.field are basically global scope variables because opt variable is passed into the .cgt files, we will see more about that in a second.

You might have noticed that confgen also has this .cgt format and that is to tell confgen that this file should be intepreted to create a new file removing the .cgt files added to the confgen file with it's new configuration as the example above shows with the config.ini but there is something else to mention which is the confgen.lua, aka, the confgen file.

1-- confgen.lua
2
3cg.addFile("confgen.ini.cgt")
4
5-- optionally you could also sent an output path
6-- otherwise it will output to the cwd
7-- both absolute and relative paths work
8
9cg.addFile("confgen.ini.cgt", "relative/path")
10
11-- recursively adds files inside a path
12
13cg.addPath(".config")
14
15-- You can also set an output path here
16cg.addPath(".config", "relative/path")

This is how confgen tracks a file to send to another destination and if it a .cgt file it will read the file and do any operations between <% and %>. Also, cg is a variable set by confgen for functions such as "addPath", "addFile", "doTemplate"... that should only be called in the confgen.lua file but cg also have the cg.opt which is where you set fields and values to be used inside .cgt files

Simple right? But there is more to see so stick with me.

1-- how-to-build-a-blog-the-hard-way.lua
2
3return {
4 title = "How to build a blog the hard way?",
5 lang = "eng",
6 date = "14-04-2024",
7}
8
9-- confgen.lua
10
11cg.addFile("how-to-build-a-blog-the-hard-way.html.cgt")
12
13-- Import the metadata to then be passed to opt.article
14-- to be used inside the html file in this example
15local article = require("how-to-build-a-blog-the-hard-way")
16cg.opt.article["how-to-build-a-blog-the-hard-way"] = article
17
18-- how-to-build-a-blog-the-hard-way.html.cgt
19
20<! local article = opt.articles["how-to-build-a-blog-the-hard-way"] !>
21<h1><% article.title %></h1>
22<h2><% article.date %></h2>

Here we have a simplified version of how I used confgen to build this blog, of course I made a more complex version for automation purposes but this is good enough to understand how to use the tool.

New feature here is code between <! and !> which is where we do operations that are not written into the file, for example, assignments, control flow, operations... for example:

1-- example.txt.cgt
2
3<! local i = 0 !>
4<! while i <= 5 do !>
5<% i %>
6<! i = i + 1 !>
7<! end !>
8
9-- confgen.lua
10
11cg.addFile('example.txt.cgt')
12
13-- example.txt
141
152
163
174
185

Well, that's the basics of confgen, but there is much more to talk about it such as confgenfs mounts a FUSE3 filesystem containing all the config files added to confgen.lua and processes each file whenever it's opened.

And if you like it, show some love to the LordMZTE for building this tool and give a star to the project and have fun using it, I highly recommend it.

So, this is how you build a blog the hard way.