From c1a6150d14c6bad611b1b733c36c08b23050c79a Mon Sep 17 00:00:00 2001 From: Tom Regner Date: Fri, 10 Mar 2023 15:27:39 +0100 Subject: [PATCH] Recreated tag-overview generation view --- blog/post_0017_generate_tags_overview.org | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 blog/post_0017_generate_tags_overview.org diff --git a/blog/post_0017_generate_tags_overview.org b/blog/post_0017_generate_tags_overview.org new file mode 100644 index 0000000..0498892 --- /dev/null +++ b/blog/post_0017_generate_tags_overview.org @@ -0,0 +1,52 @@ +#+title: Generate a tag info page +* Generate a tag info page +:PROPERTIES: +:TAGS: emacs orgmode tags +:END: + +July 19, 2022 -- extract tags and build tags.org 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 ~tags.org~, 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. + +#+BEGIN_SRC sh + exec {of} > tags.org + exec >&${of} + echo -e "#+TITLE: Tags\n<>\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}]] " + done +#+END_SRC + +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. + +#+BEGIN_SRC sh + 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})]]" + done + echo "[[up][/↑/]]" + done + exec {of}>&- +#+END_SRC -- 2.38.4