Bootstrapping a Blog: Sorting The Index
Feb 19th 2024
A currently annoying aspect of this site is that the index is unordered.
Currently it looks like this:

I’d like to get the posts displayed in order, and I’d like to order them by date. At the top of each markdown post I have a frontmatter section:
Here’s the one from this post:
---
title: "Bootstrapping a Blog: Sorting The Index"
date: "02-19-2024"
author: "Alex Larsen"
---Grabbing that key out of the frontmatter on the markdown file would be the best way to go about this. I just recently found a handy tool yq that allows for frontmatter queries. Sure enough running it against this file:
λ yq --front-matter=extract '.date' bootstrapping_a_blog_sorting_the_index.md
02-19-2024Which is exactly what I need.
Now it’s tempting to write a script to sort this for me with the custom command, but I’d like to only rely on coreutils or other command line tools where possible. Let’s see if we can’t get this with just bash, sort, and yq.
First off, here’s what the relevant portion of my build.sh script looks like:
for p in ./posts/*.md; do
...
done;Let’s see if we can’t start by turning that into a variable:
POSTS=(./posts/*.md)
for p in $POSTS; do
...
done;