#!/bin/bash cd ~/Dropbox/Apps/Blot/Posts # Get current date/time today=$(date +"%Y%m%d%H%M") # Set output file fn=../Pages/page-tag-cloud.md # Ensure correct line-endings for filename in *.md; do if grep -rq $'\r' "$filename"; then content=$(tr -d '\015' < $filename) echo "$content" > $filename fi done # Get tags from only the non-scheduled posts tags="" for filename in *.md; do postdate=$(grep "^Date:" $filename | sed 's/Date:[ ]*//' | tr -d ' :-')'000000000000' postdate=${postdate:0:12} if [[ "$postdate" -le "$today" ]]; then tags="$tags"$'\n'$(cat $filename | grep "^Tags:" | sed 's/Tags:[ ]*//' | awk -F ', ' '{for(i=1;i<=NF;i++){print $i}}') fi done # Sort and count unique tags tags=$(echo "$tags" | sed '/^$/d' | 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 "
" >> $fn # Add the URL(s) echo "" >> $fn echo "[1]: http://blog.hejki.org/post/102115323478/scriptogram-seznam-tagů" >> $fn cd ..