Website Generation With Unix Coreutils
As a newbie website author, my process of post-writing consisted of:
- Copying the last post I made in raw HTML
- Erasing the paragraphs and writing new ones
- Pushing to my server with scp
I knew about static site generators, but they all seemed unpleasant and bloated, and not worth the trouble if I'm just going to be writing plain HTML blog posts every few weeks or so. I was on the search for something better, though, since this bad workflow discouraged me from writing. If I wanted to make a change to the footer of my website, I'd have to come up with a clever sed command to add what I wanted to every page, and then re-push. I even wrote out most of the rss feed by hand!
Momi's post was a huge help in getting me set up and guiding me around some of the nuances of the tools I used.
ssg5 is a static site generator made with 180 lines of shell script. I would have never thought I could simply read my site generator. I'll document my experience porting my site over here similarly to Momi's post.
To generate an rss feed, rssg is a companion script that generates a feed from your webpages. rssg is kind of finicky, though, and needs a list of posts laid out a certain way to generate correctly. I took a trick out of Anjan's book and wrote my own script to generate a list for rssg to use. Figuring out what rssg was looking for was definitely the hardest part of the setup, and it took me a few tries to wrap my head around how it was generating.
Anjan's post mentions having to change the daterfc822() function in rssg to fit his date format / keep compatibility with GNU coreutils. Since my dates were already in MM-DD-YYYY format, I was able to pretty much omit the function from my copy.
Since I wanted a different header based on whether the user was looking at a blogpost or the index, I made some small changes to ssg5. I separated the header definition into a "default header" and an "index header" in main():
h_file="$src/_header.html" h_index_file="$src/_header-index.html" f_file="$src/_footer.html" test -f "$f_file" && FOOTER=$(cat "$f_file") && export FOOTER test -f "$h_file" && DEFHEADER=$(cat "$h_file") && export DEFHEADER test -f "$h_index_file" && INDEXHEADER=$(cat "$h_index_file") && export INDEXHEADER
Then in render_md_files_markdown_pl(), I added a check to match the filename with index.md. This change is also pretty similar to the one in Momi's post.
if $(echo "$1/$f" | grep "index.md" > /dev/null); then HEADER="$INDEXHEADER" && export HEADER else HEADER="$DEFHEADER" && export HEADER fi
To push my website, I wrote a script that just runs the programs in order and then rsyncs it to my server. It makes and deploys super quick, and has really gotten me back in the groove of writing again. Thanks again to Anjandev Momi for writing a great introduction to something I probably would never have heard of otherwise.
home | blog index | rss | contact me | PGP public key?