From 74e8e1ad4d02d1c2e39302b5bf2c85ec88c99ad5 Mon Sep 17 00:00:00 2001 From: hitlerrip Date: Mon, 28 Jul 2025 14:49:07 +0200 Subject: init created the initial version of my website build script --- build.sh | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100755 build.sh (limited to 'build.sh') diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..906167f --- /dev/null +++ b/build.sh @@ -0,0 +1,172 @@ +#!/bin/sh + +# hitler.rip +# script to build my website using pandoc +# © 2025 hitler.rip +# licensed under AGPLv3-or-later; see licenses/code.md for more information + +echo "[build] starting to build webpage..." + +rm -rf ./tmp/ +rm -rf ./web +mkdir -p ./con/ +mkdir -p ./src/articles/ +mkdir -p ./tmp/articles/ +mkdir -p ./web/articles/ +mkdir -p ./web/licenses/ +mkdir -p ./dir/ + +touch ./con/header.html +touch ./con/footer.html +touch ./con/style.css +touch ./con/rss-header.xml +touch ./con/rss-footer.xml +touch ./con/contact.md +touch ./src/index.md +touch ./src/articles/index.md + +echo "[build] writing index..." +cd ./src/ + +for i in *.md; do + + echo "[build] converting: $i" + + filename=$( echo "$i" | rev | cut -c4- | rev ) + + pandoc "$i" -o ../tmp/"$filename".html \ + -f gfm -t html5 \ + --lua-filter=../con/links.lua + + if [ "$filename" == "index" ]; then + + pandoc ../con/contact.md -o ../tmp/con-contact-tmp-file.html \ + -f gfm -t html5 \ + --lua-filter=../con/links.lua + + cat ../con/header.html \ + ../tmp/"$filename".html \ + ../tmp/con-contact-tmp-file.html \ + ../con/footer.html \ + > ../web/"$filename".html + + cat "$i" \ + ../con/contact.md \ + > ../web/"$filename".md + + else + + mkdir -p ../web/"$filename"/ + + cat ../con/header.html \ + ../tmp/"$filename".html \ + ../con/footer.html \ + > ../web/"$filename"/index.html + + cp "$i" ../web/"$filename"/index.md + + fi + +done + +echo "[build] writing articles..." +cd ./articles/ + +for i in *.md; do + + echo "[build] converting: $i" + + filename=$( echo "$i" | rev | cut -c4- | rev ) + + pandoc "$i" -o ../../tmp/articles/"$filename".html \ + -f gfm -t html5 \ + --lua-filter=../../con/links.lua + + if [ "$filename" == "index" ]; then + echo "[build] skipping index file for later..." + else + + mkdir -p ../../web/articles/"$filename"/ + + cat ../../con/header.html \ + ../../tmp/articles/"$filename".html \ + ../../con/footer.html \ + > ../../web/articles/"$filename"/index.html + + cp "$i" ../../web/articles/"$filename"/index.md + + fi + + cp "$i" ../../web/articles/ + + # sort this by date + + if [ -e "$filename".meta ]; then + source ./"$filename".meta + # `.meta` is a simple shell script that uses `export` to + # set some variables, notably: + # WEBMETA_TITLE (title string) + # WEBMETA_DATE (date string YYYY-MM-DD) + # WEBMETA_AUTH (author string) + # WEBMETA_SUMMARY (summary string) + # please note that you have to actually check if this data is correct + # and you should not just import random `.meta` files as they can arbitrarily + # execute code on your system and are directly injected into the HTML. + export WEBMETA_BASELINK="https://hitler.rip/articles/" + # you will also have to manually change this link to the final destination + # of your articles so that the RSS feed can successfully link there. + + touch ../../tmp/articles/gen-articles-tmp-list.html + tee -a ../../tmp/articles/gen-articles-tmp-list.html > /dev/null << EOF +
+

$WEBMETA_TITLE

+
$WEBMETA_DATE by $WEBMETA_AUTH
+

$WEBMETA_SUMMARY

+
+EOF + + touch ../../tmp/articles/gen-articles-tmp-rss.xml + tee -a ../../tmp/articles/gen-articles-tmp-rss.xml > /dev/null << EOF + + $WEBMETA_TITLE + $(date -d "$WEBMETA_DATE" +"%a, %d %b %Y %H:%M:%S +0000" ) + $WEBMETA_AUTHOR + $WEBMETA_SUMMARY + /$filename + /$filename + +EOF + + fi + +done + +cd ../.. + +echo "[build] generating feed..." + +cat ./con/header.html \ + ./tmp/articles/index.html \ + ./tmp/articles/gen-articles-tmp-list.html \ + ./con/footer.html \ + > ./web/articles/index.html + +cat ./con/rss-header.xml \ + ./tmp/articles/gen-articles-tmp-rss.xml \ + ./con/rss-footer.xml \ + > ./web/articles/feed.xml + +echo "[build] copying static files..." + +cp ./con/style.css ./web/style.css +cp ./con/icon.png ./web/icon.png + +cp ./licenses/* ./web/licenses/ + +cp -r ./dir/* ./web/ + +echo "[build] removing temporary build files..." + +rm -rf ./tmp + +echo "[build] done!" -- cgit v1.2.3