Generate a tag info page

July 19, 2022 – extract tags and build during export

Side note: I failed my first attempt to offload 100 times in a year… I will probably take this challenge on a second time, but not right now.

But to the matter at hand: I started tagging the posts here a while bag. This is a static web-site generated during publishing by emacs org-mode. I don’t want to switch to another generator, but I do want to use the tags to generate an overview with a section for every tag listing links to the posts tagged with it.

To that effect, I added a code block to the index page, that does not get exported and so does not alter the index page in any way, but as a side effect generates a new file, that will be exported by org-publish, functioning as a poor-mans tag overview/post list.

It’s a zsh script that relies on rg in addition to grep, sed and sort. The first step uses rg to extract the TAGS line from the post files, and use the other tools to build a sorted list of tags.

  exec {of} >
  exec >&${of}
  echo -e "#+TITLE: Tags\n<<up>>\n* List of tags and articles\n"
  declare -a usedtags
  usedtags=($(rg -NI -e ":TAGS:" ./ | grep -v 'rg -N' | sed 's/:TAGS://' | sed "s/ /\n/g" | sort -u ))
  for i in ${usedtags[@]}; do
      echo -n "[[*${i}]] "

In a second step we iterate over this list and use rg again to find all post-files containing the tag and generating org header lines and lists with links, in the same way the link lists on the index page are build, although these are done with page modifying code-blocks.

  echo -e "\n"
  for i in ${usedtags[@]}; do
      echo "*** ${i}"
      for j in $(rg -Nl --sort path -e ":TAGS:.* ${i}.*" ./); do
          echo "- [[$(sed 's/\.org/.html/' <<< ${j})][$(grep -Po "(?<=^\* )(.+)" ${j})]]"
      echo "[[up][/↑/]]"
  exec {of}>&-