In case you haven't read about it, I made myself a static page generator.

But why? Why go through all the trouble?

Well, it started out to be very naive. I didn't like the idea of having to maintain the menu on every page, and it was really not so much trouble. I spent about a weekend to put together what I'm using now, there are still many tweaks I'd like to do but it's sufficient for now. Now, it feels very fluid.

So why not use a dynamic language like php?

The thing is I didn't want to use a framework, it would have been a much bigger learning curve. Plus I had to choose one and stick with it. In fact, I'm really wondering why use dynamic pages for personal pages anymore because we can use JQuery to manipulate the DOM objects just as easily on the client side.

And if a call to the server is needed, make an Ajax call to the .php page. Since this isn't an enterprise app, I won't need a lot of database dependent logic on the backend, a HTML site with light backend is more than enough. In fact, NibbleBlog doesn't even use a database

What does the static generator do?

Wow, I just realized I haven't described what it does. Well, it reduces amount of maintenance I have to do, now that I trust the content it generates, every time I make a change to the menu. Running the script will rebuild the menu to every page that needs it, consistently.

So before I FTP it, I could run a script to change localhost to I suppose awk would do just as well, but oh well, I use the generators to update my links when a new page is created.

There is also a bit of templating going on now, my home page is now updated using a Dashboard generation script.

How does it work?

Currently I have two generation scripts that are packaged into a bash script.
One used for menu generation, and another for general templating purpose.

Every time I create a new page, I would modify a listing file to add the new page. The file looks something like this

Text Templating::codereplace.html
Magic 8 Ball::magicball.html
Memory Test::memory.html

Very simple syntax, I use :: as delimiters. There surely will be corner cases where it will break things, but hey, there are plenty of other static generators that you can use.

The main script looks at its own file and figure out which directory it needs to traverse to.
And it goes into those directories to build the menu.


Logo:<a href="{ROOTPATH}"><img src="{ROOTPATH}/img/logo.png" /></a>

Swu's lab

Of course, I'm not using Separation of Concern very well. It wasn't really my concern :)

So far, only the homepage uses the templating script since I use that page like a menu. Surprisingly it was made generic enough to use a Model-View architecture

Next up: To allow each page to use different templates. I might never have to do that, so it will be done when I need it.

What language?

I chose Python, not that I like Python a lot or that I'm an expert, I just wanted to be familiar with it since everyone knows Python now (but hey, WebAssembly is increasing applicability of C++, YAY~~) and it came pre-installed with my new Linux-Mint installation.


I didn't feel that strongly about it, but now that I've written this, I feel EVERYONE should write a static page generator for the following reasons

  • Seemless integration with nibbleblog :)
  • You get the practice and experience
  • Doesn't take a whole lot of time because it's okay for it to be less than perfect
  • Changing environments is as easy as running a script
  • Updates pages consistently
  • It fits YOUR style exactly
  • No need to learn another generator unless you desire fancy functionalities, in that case, isn't it better to use a dynamic language like php or RoR
  • It might turn out to be more powerful than expected!

Github: Static Generator Repository