Aug 28 2015 0

Creating a tag cloud

Although supports tags, it does not have a page displaying all of the tags used on your blog. A post will list the tags associated with it, and from a specific tag a page is available to list the posts sharing the same tag.

Using a simple bash script I generate a page containing all the tags I have been using in my posts. For each tag it also lists in how many posts it appears. Since the script is using bash (as well as the commands cat, grep, sed, awk, sort and uniq) it will only run on a Unix-based system. Maybe it will work on cygwin (“Get that Linux feeling - on Windows”) as well, but I have not tested this.

The script looks for all Markdown files (*.md) within my Blot folder (~/Dropbox/Apps/Blot/Posts) and outputs a file named ../Pages/

My script is inspired on the this post by Hejki’.

The shell script


cd ~/Dropbox/Apps/Blot/Posts
tags=$(cat *.md | grep "^Tags:" | sed 's/Tags:[ ]*//' | awk -F ', ' '{for(i=1;i<=NF;i++){print $i}}' | sort -f | uniq -c)

# Create header for the page
echo "Title: Tags" > $fn
echo "Page: yes" >> $fn
echo "Permalink: page-tags" >> $fn
echo "Date: "`date +"%Y-%m-%d %H:%M"` >> $fn

# Output intro text
echo "" >> $fn
echo "# Tag cloud" >> $fn
echo "" >> $fn
echo "This pages serves as a replacement for a tag cloud. This page is generated using a shell script. " >> $fn
echo "This page is inspired on the [following post][1]." >> $fn
echo "" >> $fn

# Output the tags
echo "<div class=\"floatlist\"><ul>" >> $fn
echo "$tags" | awk '{print "<li><a href=\"" tolower($2) "\">"$2"</a> <span class=\"badge\">"$1"</span></li>"}' >> $fn
echo "</ul></div>" >> $fn

# Add the URL(s)
echo "" >> $fn
echo "[1]:ů" >> $fn

cd ..

Updates to the script

  • (2015/09/01) Date field is now also being set to the date/time the Markdown file is generated

Previous post
Improving syntax highlighting Since I have turned on line-numbering for code blocks, it gets applied to all blocks of code. This has a couple of downsides Numbering and
Next post
Improving Wi-Fi at home I live in an apartment which has a lot of square feet. The modem of my ISP is located in the Closet/Metering cupboard, meaning the Wi-Fi
This blog is powered by Blot