added gen_index script
authorMatthewOwens <matthew@owens.tech>
Fri, 17 Jul 2020 20:15:44 +0000 (21:15 +0100)
committerMatthewOwens <matthew@owens.tech>
Fri, 17 Jul 2020 20:15:44 +0000 (21:15 +0100)
scripts/gen_index.sh [new file with mode: 0755]
scripts/posts.awk [new file with mode: 0644]

diff --git a/scripts/gen_index.sh b/scripts/gen_index.sh
new file mode 100755 (executable)
index 0000000..c772b25
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+#[ $# -ne 1 ] && exit 1
+
+POSTS_DIR=posts
+POSTS=$(ls $POSTS_DIR | sed 's/ /\r\n/')
+MATCH="^([0-9]{1,4})-([0-9]{1,4})-([0-9]{1,4})-([^\.]+)(.*)"
+
+sed "s|TITLE|<title>Matthew Owens</title>|" includes/head.html
+cat includes/header.html
+ls $POSTS_DIR | sed -Ee 's/ /\n/' -e "s/$MATCH/\1 \2 \3 \4/" | awk -f scripts/posts.awk
diff --git a/scripts/posts.awk b/scripts/posts.awk
new file mode 100644 (file)
index 0000000..fe2e577
--- /dev/null
@@ -0,0 +1,16 @@
+BEGIN {
+       #OFS=""
+       #FS="[-.]"
+       print "<ul>"
+}
+
+{
+       file = sprintf("%s-%s-%s-%s", $1, $2, $3, $4)
+       string = sprintf("%s/%s/%s - %s", $1, $2, $3, $4)
+
+       printf("\t<li> <a href=\"/posts/%s.html\">%s</a></li>\n", file, string)
+}
+
+END {
+       print "</ul>"
+}