From 619508a37640e509ffbee1fc820205d83846a337 Mon Sep 17 00:00:00 2001
From: MatthewOwens <matthew@owens.tech>
Date: Fri, 17 Jul 2020 21:15:44 +0100
Subject: [PATCH] added gen_index script

---
 scripts/gen_index.sh | 11 +++++++++++
 scripts/posts.awk    | 16 ++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100755 scripts/gen_index.sh
 create mode 100644 scripts/posts.awk

diff --git a/scripts/gen_index.sh b/scripts/gen_index.sh
new file mode 100755
index 0000000..c772b25
--- /dev/null
+++ b/scripts/gen_index.sh
@@ -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
index 0000000..fe2e577
--- /dev/null
+++ b/scripts/posts.awk
@@ -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>"
+}
-- 
2.20.1