1 --- 2 title: "Website Generation with Unix Coreutils" 3 date: 2020-05-08 4 draft: false 5 --- 6 7 As a newbie website author, my process of post-writing consisted of: 8 9 - Copying the last post I made in raw HTML 10 - Erasing the paragraphs and writing new ones 11 - Pushing to my server with scp 12 13 I'm serious! 14 15 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! 16 17 I came across [this post](https://momi.ca/posts/2020-07-21-ssg.html) by [Anjandev Momi](https://momi.ca/index.html), which inspired me to take my own dive into a new blogging setup that this site is being built with as of now. 18 19 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. 20 21 [ssg5](https://www.romanzolotarev.com/ssg.html) 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. 22 23 ### rssg 24 25 To generate an rss feed, [rssg](https://www.romanzolotarev.com/rssg.html) 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](indexgen.sh) 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. 26 27 Anjan's post mentions having to change the date_rfc_822() 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. 28 29 ### ssg5 30 31 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(): 32 33 <pre> 34 h_file="$src/_header.html" 35 h_index_file="$src/_header-index.html" 36 f_file="$src/_footer.html" 37 test -f "$f_file" && FOOTER=$(cat "$f_file") && export FOOTER 38 test -f "$h_file" && DEFHEADER=$(cat "$h_file") && export DEFHEADER 39 test -f "$h_index_file" && INDEXHEADER=$(cat "$h_index_file") && export INDEXHEADER 40 </pre> 41 42 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. 43 44 <pre> 45 if $(echo "$1/$f" | grep "index.md" > /dev/null); then 46 HEADER="$INDEXHEADER" && export HEADER 47 else 48 HEADER="$DEFHEADER" && export HEADER 49 fi 50 </pre> 51 52 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](https://momi.ca/index.html) for writing a great introduction to something I probably would never have heard of otherwise.