summaryrefslogtreecommitdiff
path: root/build-index.sh
diff options
context:
space:
mode:
authorAndré Fincato <work@andrefincato.info>2020-08-03 00:08:41 +0200
committerAndré Fincato <work@andrefincato.info>2020-08-03 00:08:41 +0200
commit44f39d7679e8a10d0c0e2736620751fd8deb8bf4 (patch)
tree0e346c5d756fca2cfc8e86e3ece84faedd587d17 /build-index.sh
parentd30e1131d74f53e775b1b9e749c70d4f9beaffab (diff)
sketching out (wip) build-index script
Diffstat (limited to 'build-index.sh')
-rwxr-xr-xbuild-index.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/build-index.sh b/build-index.sh
new file mode 100755
index 0000000..5fd7d14
--- /dev/null
+++ b/build-index.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+INPUT=$1
+# OUTPUT=$3
+
+# COMMIT_DATE=$(git log -n 1 --pretty=format:%cd --date=format:'%Y-%m-%dT%H:%M:%S' -- $INPUT)
+# COMMIT_HASH=$(git log -n 1 --pretty=format:%h -- $INPUT)
+
+# find all files not named `index.txt` in $INPUT folder,
+# extract text after the `title: ` field and append it to file
+# find $INPUT -name "*.txt" ! -name "index.txt" -type f -exec sed -n 's/^title:[[:space:]]*//p' {} \; > output.txt
+
+# cd $INPUT
+# find . -name "*.txt" ! -name "index.txt" -type f \
+# -exec sed -n 's/^title:[[:space:]]*//p' {} \;
+
+extracttitle () {
+ local file=$1
+ sed -n "s/^title:[[:space:]]*//p"
+}
+
+{
+ printf '%s\n' "# All posts"
+ # local f
+ for f in ????-??-??-*.md; do
+ printf -- ':::\n[%s](%s)\n:::indexTitle\n\n:::\n%s\n:::indexDate\n\n' \
+ "$(extracttitle "$f")" "${f/%.txt/.html}" "${f:0:10}"
+ md2html "$f"
+ done | tac
+ } > output.txt
+
+