summaryrefslogtreecommitdiff
path: root/bin/makewritindex
diff options
context:
space:
mode:
Diffstat (limited to 'bin/makewritindex')
-rwxr-xr-xbin/makewritindex53
1 files changed, 53 insertions, 0 deletions
diff --git a/bin/makewritindex b/bin/makewritindex
new file mode 100755
index 0000000..5562c85
--- /dev/null
+++ b/bin/makewritindex
@@ -0,0 +1,53 @@
+#!/bin/sh -e
+
+. ./config
+
+writings_by_cat() {
+ for file in "$DIR_WRITINGS"/*."$EXT_WRITINGS"; do
+ case "$(sed -n '2p' "$file") " in
+ *" $1 "*) echo "$file" ;;
+ esac
+ done
+}
+
+if [ -z "$1" ]; then
+ cats="$(categories "$DIR_WRITINGS"/*."$EXT_WRITINGS")"
+ writings="$DIR_WRITINGS/*.$EXT_WRITINGS"
+ all=1
+else
+ cats="$1"
+ writings="$(writings_by_cat "$1")"
+fi
+
+writings=$(for f in $writings; do
+ date="$(date -d "$(sed -n '3s/^; //p' "$f")" "+%s")"
+ printf '%s %s\n' "$date" "$f"
+done | sort -rn | cut -f2 -d' ')
+
+cat <<EOF
+<nav class="categories">
+$([ -z "$all" ] && echo "#<a class=\"category\" href=\"/writings/\">all</a>")
+$(for c in $cats; do echo "#<a class=\"category\" href=\"/writings/$c\">$c</a>"; done)
+</nav>
+<ul class="writ-index">
+EOF
+
+for f in $writings; do
+ title=$(sed -n '1s/^; //p' "$f")
+ cats=$(sed -n '2s/^; //p' "$f")
+ date="$(date -d "$(sed -n '3s/^; //p' "$f")" "+%d %b %Y")"
+ file="$(basename "$f" .md)"
+
+ cat_links=$(echo "$cats" | tr ' ' '\n' | while read -r cat; do
+ echo "#<a class=\"category\" href=\"/writings/$cat\">$cat</a>"
+ done | tr '\n' ' ')
+
+ cat <<EOF
+<li class="writing">
+<span>$date&nbsp; <a href="/writings/$file">$title</a></span>
+<span>$cat_links</span>
+</li>
+EOF
+done
+
+echo "</ul>"