Blog IndexPosts by TagHome

Org-Mode Tag Index (for blogging!)

Posted <2015-09-08 Tue 02:26> by Aaron S. Jackson.

Well I decided to create a very disgusting bash script to create the pages listing the tags. It actually works quite well, but solution is not ideal. Ideally I would have created it in Elisp, but I am not a great lisp programmer and I can hack things together much more quickly in bash.

Here it is…


mkdir -p ~/public_html/blog/tags
rm -f ~/public_html/blog/tags/*

cd ~/public_html/blog/org

listing=`grep ^\#\+FILETAGS\: *.org | sort -r` # get a files and their tags

# get a list of all the posts
posts=`echo "$listing" | awk '{ print $1 }'`
posts=`echo "$posts" | rev | cut -c 13- | rev`

# get the tags for each post
posts_tags=`echo "$listing" | awk '{ print $2 }'`

# create a list of all tags
all_tags=`echo "$posts_tags" | tr ":" "\n" | grep -v '^$'`
all_tags=`echo "$all_tags" | sort | uniq | sort`

echo "#+TITLE: Tags" > ~/public_html/blog/tags/

# create a tag file for each tag
while read -r tag; do
    count=`grep ^\#\+FILETAGS\:.*\:$tag\: *.org | wc -l`
    echo "$tag appeared $count times"

    echo "#+TITLE: Tag: $tag" > ~/public_html/blog/tags/$
    echo "- [[./$tag.html][$tag]] ($count)" >> ~/public_html/blog/tags/
done <<< "$all_tags"

# populate the tag files
while read -r file; do
    # get the file tags and pop it off from the "stack"
    tags=`echo "$posts_tags" | head -n1 | tr ':' '\n' | grep -v '^$'`
    posts_tags=`echo "$posts_tags" | tail -n +2`

    # get the post title and date
    title=`cat $file | grep ^\#\+TITLE\: | cut -c 10-`
    date=`cat $file | grep ^\#\+DATE\: | cut -c 10- | rev | cut -c 2- | rev`
    date=`date -d"$date" +"%d %B %Y %H:%M"`

    # for each tag, add this file to that tag file...
    while read -r tag; do
    echo "- [[../$file][$date - $title]]" >> ~/public_html/blog/tags/$
    done <<< "$tags"
done <<< "$posts"

Wanting to leave a comment?

Comments and feedback are welcome by email (

Tags: emacs hacks

Blog IndexPosts by TagHome

Copyright 2007-2022 Aaron S. Jackson (compiled: Sun 2 Jan 00:24:10 GMT 2022)