commit c85f2dc68f5efe827e2d02d9760827aae632da74 Author: kageru Date: Wed Apr 1 22:13:13 2020 +0200 initial commit diff --git a/blog-refresh.sh b/blog-refresh.sh new file mode 100644 index 0000000..4c4c130 --- /dev/null +++ b/blog-refresh.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +output() { + echo "$1" >> index.html +} + +html_entry() { + output '' + path="$1" + time="$2" + title="$3" + output "$title" + output "$time" +} + +create_entry() { + path="$9" + outpath="content/$(basename "$path" .md).html" + # convert new markdown posts to html + pandoc "$path" -t html > "$outpath" + # then add it to the index + title="$(rg 'h1' "$outpath" | head -n1 | rg -o '(?<=>).*(?=<)' --pcre2)" + created=$(git log --follow --format=%as "$path" | tail -1) + html_entry "$outpath" "created on $created" "$title" +} + +has_updates() { + git fetch &> /dev/null + diff="$(git diff master origin/master)" + if [ "$diff" ]; then + return 0 + else + return 1 + fi +} + +cd /home/nginx/html/blog +if has_updates; then + git pull + rm index.html + output '

Blog index

' + output '' + ls -ltu src/*.md | tail -n+1 | while read f; do create_entry $f; done + html_entry "legacy" "before 2020" "Older posts" + output '' + output "" +fi