1 # Website Generation With Unix Coreutils 2 ## 08/05/2020 3 4 As a newbie website author, my process of post-writing consisted of: 5 6 - Copying the last post I made in raw HTML 7 - Erasing the paragraphs and writing new ones 8 - Pushing to my server with scp 9 10 I'm serious! 11 12 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! 13 14 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. 15 16 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. 17 18 [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. 19 20 ### rssg 21 22 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. 23 24 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. 25 26 ### ssg5 27 28 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(): 29 30 <pre> 31 h_file="$src/_header.html" 32 h_index_file="$src/_header-index.html" 33 f_file="$src/_footer.html" 34 test -f "$f_file" && FOOTER=$(cat "$f_file") && export FOOTER 35 test -f "$h_file" && DEFHEADER=$(cat "$h_file") && export DEFHEADER 36 test -f "$h_index_file" && INDEXHEADER=$(cat "$h_index_file") && export INDEXHEADER 37 </pre> 38 39 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. 40 41 <pre> 42 if $(echo "$1/$f" | grep "index.md" > /dev/null); then 43 HEADER="$INDEXHEADER" && export HEADER 44 else 45 HEADER="$DEFHEADER" && export HEADER 46 fi 47 </pre> 48 49 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.