In the era of dynamic web applications, static site generators (SSGs) have regained popularity for their simplicity, speed, and security. This blog post explores my journey in building a custom static site generator using C++, designed to power this very website. Unlike popular tools like Jekyll or Hugo, this project offers a lightweight, hands-on approach to generating static HTML pages from Markdown files, with support for themes, tags, and RSS feeds.
Choosing C++ for an SSG might seem unconventional, given the dominance of languages like Python or JavaScript. However, C++ brings unique advantages:
This static site generator is a command-line tool that transforms Markdown files in a content
directory into a public
directory of HTML pages. Key features include:
MarkdownParser
class extracts front matter (title, date, description, tags) and converts the body to HTML.PageGenerator
class loads templates, replaces placeholders, and writes output files.Makefile
compiles the C++ code, and a script regenerates the site on file changes.public
folder is served via a simple HTTP server or deployed to a host like Netlify.content/blogs/new-post.md
../build/zenith
to generate public/blogs/new-post.html
.http-server public -p 8080
.scp -r public/* user@server:/var/www/html/
.Explore the source code on my GitHub and try building your own SSG!
Happy coding!