Hugo? More like, No-Go

Driven largely by a staunch refusal to learn anything too new, I've decided to try my foolish hand at writing one of these “static site generators”. That is to say, I've decided to pretend a task is very very simple, and pray that my needs never outgrow my mediocre bash skills.

Basically, I'm tired of writing brackety tags everywhere, so I have a little converter from plain text to HTML. There's a template.html file and an index.template.html file. The first is the basis for individual posts, and the second is used to generate a list of links to each post.

This script is incredibly naive. It more or less copy pastes the text in a given post file straight into the body of the template.html file. But it does use the first line of the file as both the header and the name of the link, which is kinda fun. And I can just add HTML tags wherever I want, if I do feel like adding some flair.

At some point, I could try to convert this into a real project with my dear friend Rust, but for now that's 2 hard.

The best part of this whole thing is that I don't even have a way to host it, yet. So for now, write.as, whoo!

#100DaysToOffload

I wanted this post to be longer, but instead I added comments to my code. So here's the script so far:

#!/bin/bash

## Replace backticks with <div>
# cat test | sed 's/`\(\w\)/<div>\1/g' | sed 's/\(\w\)`/\1<\/div>/g'

# Delete old versions of pages
rm pages/*

# Folder with plaintext posts
cd posts

# Accrue link text
links=""
for f in `ls -t`; do
    # First line is the title
    title=$(head -n 1 $f)

    # Stupidly replace newlines so sed can process them
    content="<p>$(tail -n +3 $f | tr '\n' '~' )"

    # Convert two once-newlines into paragraph tags
    content="$(echo "$content" | sed 's/~~/<\/p>\n<p>/g' | sed 's/~/\n/g' | sed '$ d')"

    # Replace the #title and #content markers with the new strings
    template=$(cat ../template.html)
    output=$(echo "${template/\#content/$content}")
    output=$(echo "${output/\#title/$title}")

    # Save this text into a new html file,
    # named after the original post text
    echo $output > "../pages/${f}.html"

    # Append a link to the new page
    links="$links<a href=\"pages/$f.html\">$title</a><br>"
done
cd ..

# Insert link text into index template
index=$(cat index.template.html)
index=$(echo "${index/\#links/$links}")

# Create index file
echo $index > index.html