Welcome to my revamped blog that I made with my latest tinker project, poogo.
Poogo is a static-site generator written in bash, which utilizes the Github markdown API to convert Markdown into HTML.
With this I can say goodbye to Hugo (sudo emerge --unmerge hugo
) and stop complaining about how I don't want to learn Hugo
themes or figure out how to work it. I will say that Hugo is quite nice and
simple enough, but I don't even need such power for my blog that has zero
readers and is hosted on Github Pages. So, I finally convinced myself to
frantically slap together a single bash(1)
script that can do everything I
need.
I wanted to create a simple tool for a simple blog. Also, it's pretty fun to push Unix tools to the limit and scour StackOverflow looking for the coolest one-liners and tricks.
Here is what I needed:
Solutions:
-ot / -nt
on fileslb
I got to the MVP after only tinkering on and off for a few days. Basically using shell-driven development (not as cool as a REPL, but pretty good!) and hacking stuff together until it works. I am not super proud of the code itself, but I didn't set out to write the most beautiful and robust bash SSG (one probably exists).
It was really relaxing to not have to to care about code cleanliness or whether or not someone else can read it. Just coding to get something done. Perhaps this is a side effect of using a language that lets you bend the rules and do wacky stuff.
There is also something satisfying about solving something using
a Unix Philosophy way instead of just installing some new tool and having to
learn the ecosystem. Spending time learning more sed(1)
is pretty amazing,
even if it sometimes feels inelegant or the solution is cryptic at first glance.
Here's a weird sed
line that I learned:
# extract the "title" of a post for a HTML <title>, a markdown '#' header from a
# file, or fallback to the title found in the <header> markdown file
extract_title() {
s='/# .*/{s/# (.*)/\1/p;Q};q1' # returns 1 on a non-match
# now we can fallback if the first match fails
sed -rn "$s" "$1" || sed -rn "$s" "$HEADER_MD"
}
Since sed
doesn't have a return code of 1
when there is no match, you have
to do a little trick using /matchRegex/s command/options
instead of the
traditional s/find/replace/options
.