Creating a static page generator

There seems to be a plethora of static site generators available, and I think they're all doing it wrong.

I think it should be handled as a simple makefile, and here is my take on it;

MD      = markdown
ORDER   = -

.SUFFIXES: .html .md

    ${MD} ${MDFLAGS} <$< | cat ${ORDER} >$@

    ls -1 *.md | sed 's/.md$$/.html/' | xargs make

MD is your markdown processor. MDFLAGS is any additional flags passed to MD (this is left intentionally blank in my example in case you want to add anything.) and ORDER is the order in which files should be concatenated, where - is the output of the markdown processor.

i.e. if you want to add a header and footer to the output file, you would change it to

ORDER = header.html - footer.html

The way that this works is due to us adding the suffix rule;


which means we execute the following line

    ${MD} ${MDFLAGS} <$< | cat ${ORDER} >$@

on every file with the .md suffix, and that the line should be a recipe on how to create a .html file from it.

We also need the line

.SUFFIXES: .md .html

to declare both .md and .html files as valid file suffixes.

The all rule always will be ran first, and in this example we're using recursion to get away from GNU's horrible $(wildcard) extension.

If you're running linux, and your filesystem supports it, you can use inotifywait to wait for filesystem events and run the makefile on change.

inotifywait -m -e modify . | while read