I’m writing a blog
Yes, you’ve read it right; I’m going to write blogs for my website now and then. We’ll see how often and how regular, but I don’t expect much. I never did this before, so let’s try it out. There are no expectations or wants towards me, to write a blog, but I’ve read some in the last months and now think it’s cool to have my own blog.
I guess it’s part of the homelabbing journey, which comes with having an own website and even before this point a “blogs” subpage. Maybe it’ll be fun; maybe there will only be one or two blogs. But it’s as always at some point in the homelab - try and error.
The content
Although this is more a symbolic blog, for starting this “experience”, I want to give you at least something to read. So the content of this first blog will be - as I saw on some other “first blogs” - the tech behind the blog. How this page, you’re reading, is served to you.
In my procrastination phase for my exams, I thought it’d be cool to have an automatic markdown to HTML parser. This happened, of course, with the underlying motive of maybe writing my own blog (as you can predict, I’m writing this blog in markdown). I wanted to to this in C, because I think it’s a good programming language, especially when working with Linux. As I tried doing this, I realized I had way less knowledge about C then I thought. So I searched the web and found a C library, which is doing exactly what I want - cmark.
After tinkering around with it and trying it out, I still needed something to automate this. I wanted to make it automatic from the beginning, because typing in the necessary commands every time a new file should be converted is waay to much effort. At some point, I’ll write the program of reading and converting (through cmark) and exporting the file myself. For the moment I’ll just use the cmark command in the shell.
My thought was to have a folder where I just drop the markdowns, and it would be automatically converted into a HTML folder. So far so good. I needed something to screen the folder and trigger the converter. But luckily I found a post on Stack Overflow - where else - from a person who wanted to monitor a folder as well. There I read about “inotify”, which was more than suitable for my project.
After trying it out a bit, I went to write a shell script for my purposes. It monitors my wished directory, and if there is a file that is new or edited it will converted into HTML via cmark. I made a systemd service to run the script permanently.
The code
WATCH_DIR="./markdown"
HTML_DIR="./html"
ARG1="-t html --smart --unsafe"
inotifywait -m -r -q -e close_write,create,move --format "%f" --include '.*\.(md)$' "$WATCH_DIR" | while read FILE
do
NAME="${FILE%.*}"
echo "A change happened on $WATCH_DIR/$FILE"
/usr/bin/cmark $ARG1 $WATCH_DIR/$FILE > $HTML_DIR/$NAME.html
echo "build $HTML_DIR/$NAME.html"
sleep 5
done
The inotifywait loop watches the directory, and if there is something happening (edit, create, or move), it triggers the cmark command. It only reacts to .md files, so if other files are dropped there, the script isn’t trying to convert the file. The cmark converts the markdown file into a HTML file and places the file in the wanted HTML folder. The ´´´–smart´´´ argument makes formatting simpler, and the the --unsafe argument allows me to insert raw HTML to the markdown file. I used the variable because it was simpler for me at this point to add arguments to the command.
I separated the markdown and HTML directories and defined the paths as variables so I can change them the way I need it. The output is printing when a file is new or changed and prints the name of the file with the path.
<head>
<title>I'm writing a blog </title>
<link rel="stylesheet" href="../../static/css/blogs.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="../../static/assets/Logo_BaumSplitter41_transparent.png"/>
</head>
I have to place the path of the CSS file in the markdown like shown below so I can use it for the blog post. As well, I added there the title of the blog, the icon of the page, and the metadata. Unfortunately, the path of files hardcoded in the markdown files, so if I have to change the directory structure, I need to edit this everywhere. But I built a proper, scalable directory structure before, so this should not be a problem.
You can view the whole codebase in my git repository.
The workflow
At this point, it’s time for a conclusion and summary. What I have to do, if I want to make a blog, is, of course, to write it first. Then I drop the markdown file into the prepared markdown folder. The script is going to convert it automatically into a HTML file and places in its preserved directory. I still have to insert the hyperlinks of the new blog to my blogs page, but that’s a sacrifice I’m willing to make. It’s not much work, and a git commit I’ve got to do for the blog anyway. I want to make an RSS feed in the future too. Maybe I’m able to automate these two elements with this process. There is always some improvement to do, and at least at a point in time, I don’t really have time for it. Maybe, when I get a great idea, about how I can improve this process, I’ll do it. It’s always a working process :)
With that, this first blog comes to an end. If you want to give me an opinion on this or contact me for other purposes, feel free to write via the known channels you can find on my startpage.
~ BaumSplitter41
11.06.2026, 17:15