From 2a51b9df1e2f56cb885f1db731cfa70dd05da528 Mon Sep 17 00:00:00 2001 From: hitlerrip Date: Tue, 29 Jul 2025 17:46:12 +0200 Subject: article sorting added (somewhat) proper article sorting to the build script --- README.md | 2 - build.sh | 137 ++++++++++++++++++++++-------- sort.sh | 59 ------------- src/articles/allerersterartikel.md | 1 + src/articles/allerersterartikel.meta | 1 + src/articles/besterartikel.md | 1 + src/articles/besterartikel.meta | 1 + src/articles/lol.md | 1 + src/articles/lol.meta | 1 + src/articles/zefinivderletzteartikel.md | 1 + src/articles/zefinivderletzteartikel.meta | 1 + 11 files changed, 108 insertions(+), 98 deletions(-) delete mode 100755 sort.sh create mode 100644 src/articles/allerersterartikel.md create mode 100644 src/articles/allerersterartikel.meta create mode 100644 src/articles/besterartikel.md create mode 100644 src/articles/besterartikel.meta create mode 100644 src/articles/lol.md create mode 100644 src/articles/lol.meta create mode 100644 src/articles/zefinivderletzteartikel.md create mode 100644 src/articles/zefinivderletzteartikel.meta diff --git a/README.md b/README.md index bf465f7..81bc301 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,6 @@ custom directories are not supported yet. you will have to manually edit the bui - title share options that link to id - add a copy button to code blocks -- sort articles by date, add latest article to home page - - allow user to create directories - 404 page diff --git a/build.sh b/build.sh index e7c8032..3cd53bf 100755 --- a/build.sh +++ b/build.sh @@ -46,15 +46,7 @@ for i in *.md; do convert "../con/contact.md" "../tmp/con-contact-tmp-file.html" - 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 + echo "[build] skipping index file for later..." else @@ -74,6 +66,10 @@ done echo "[build] writing articles..." cd ./articles/ +declare -A articlearr +declare -a workingarr +declare -a thebestarr + for i in *.md; do echo "[build] converting: $i" @@ -94,10 +90,7 @@ for i in *.md; do cp "$i" ../../web/articles/"$filename"/index.md - export WEBMETA_TITLE="" export WEBMETA_DATE="" - export WEBMETA_AUTH="" - export WEBMETA_SUMMARY="" if [ -e "$filename".meta ]; then echo "[build] running script: $filename.meta" @@ -111,57 +104,127 @@ for i in *.md; do # 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. + # + # NOTE: + # I do not expect to have multiple articles written on the same day + # as I am a lazy fuck. The generator below does not expect multiple + # articles to have the exact same date. + # If I were you, I would maybe add hours and minutes to the timestamps + # and maybe change this script accordingly. fi - + if [ "$WEBMETA_DATE" == "" ]; then - export WEBMETA_DATE="2001-09-11*REDACTED!*" - fi - if [ "$WEBMETA_AUTH" == "" ]; then - export WEBMETA_AUTH="Anonymous" - fi - if [ "$WEBMETA_SUMMARY" == "" ]; then - export WEBMETA_SUMMARY="redacted" + export WEBMETA_DATE="2001-09-11*" fi - if [ "$WEBMETA_TITLE" == "" ]; then - export WEBMETA_TITLE="$filename" + + articlearr["$filename"]="$WEBMETA_DATE" + + fi + +done + +echo "[build] sorting articles..." + +workingarr=($( sort -nr < <(printf '%s\n' "${articlearr[@]}") )) + +for date in "${workingarr[@]}"; do + for key in "${!articlearr[@]}"; do + if [ "${articlearr[$key]}" == "$date" ]; then + thebestarr+=("$key") fi + done +done + +for i in "${thebestarr[@]}"; do + + export WEBMETA_TITLE="" + export WEBMETA_DATE="" + export WEBMETA_AUTH="" + export WEBMETA_SUMMARY="" + if [ -e "$i".meta ]; then + echo "[build] re-running script: $i.meta" + source ./"$i".meta + # see above + fi - touch ../../tmp/articles/gen-articles-tmp-list.html - tee -a ../../tmp/articles/gen-articles-tmp-list.html > /dev/null << EOF + if [ "$WEBMETA_DATE" == "" ]; then + export WEBMETA_DATE="2001-09-11*" + fi + if [ "$WEBMETA_AUTH" == "" ]; then + export WEBMETA_AUTH="Anonymous" + fi + if [ "$WEBMETA_SUMMARY" == "" ]; then + export WEBMETA_SUMMARY="redacted" + fi + if [ "$WEBMETA_TITLE" == "" ]; then + export WEBMETA_TITLE="$i" + fi + + if [ "$i" == "${thebestarr[0]}" ]; then + tee ../../tmp/articles/gen-first-article-tmp.html > /dev/null << EOF +

Latest Post:

+
+

$WEBMETA_TITLE

+
$WEBMETA_DATE by $WEBMETA_AUTH
+

$WEBMETA_SUMMARY

+
+
See more Articles →
+EOF + tee ../../tmp/articles/gen-first-article-tmp.md > /dev/null << EOF + +## Latest Post: + +## [$WEBMETA_TITLE](/articles/$i) +###### \`$WEBMETA_DATE\` by $WEBMETA_AUTH +$WEBMETA_SUMMARY +EOF + fi + + touch ../../tmp/articles/gen-articles-tmp-list.html + tee -a ../../tmp/articles/gen-articles-tmp-list.html > /dev/null << EOF
-

$WEBMETA_TITLE

+

$WEBMETA_TITLE

$WEBMETA_DATE by $WEBMETA_AUTH

$WEBMETA_SUMMARY

EOF - touch ../../tmp/articles/gen-articles-tmp-list.md - tee -a ../../tmp/articles/gen-articles-tmp-list.md > /dev/null << EOF + touch ../../tmp/articles/gen-articles-tmp-list.md + tee -a ../../tmp/articles/gen-articles-tmp-list.md > /dev/null << EOF -## [$WEBMETA_TITLE]($filename) +## [$WEBMETA_TITLE]($i) ###### \`$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 + touch ../../tmp/articles/gen-articles-tmp-rss.xml + tee -a ../../tmp/articles/gen-articles-tmp-rss.xml > /dev/null < $WEBMETA_TITLE - $(date -d "${WEBMETA_DATE:0:10}" +"%a, %d %b %Y %H:%M:%S +0000" ) - $WEBMETA_AUTHOR + $(date -d "${WEBMETA_DATE:0:10}" +"%a, %d %b %Y %H:%M:%S +0000") + $WEBMETA_AUTH $WEBMETA_SUMMARY - /$filename - /$filename + /$i + /$i EOF - fi - done +echo "[build] generating feed..." cd ../.. -echo "[build] generating feed..." +cat ./con/header.html \ + ./tmp/index.html \ + ./tmp/articles/gen-first-article-tmp.html \ + ./tmp/con-contact-tmp-file.html \ + ./con/footer.html \ + > ./web/index.html + +cat ./src/index.md \ + ./tmp/articles/gen-first-article-tmp.md \ + ./con/contact.md \ + > ./web/index.md cat ./con/header.html \ ./tmp/articles/index.html \ diff --git a/sort.sh b/sort.sh deleted file mode 100755 index 10d64a1..0000000 --- a/sort.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# hitler.rip -# temporary script that implements sorting articles by date -# © 2025 hitler.rip -# licensed under AGPLv3-or-later; see licenses/code.md for more information - -declare -A articlearr -declare -a workingarr -declare -A thebestarr - -cd ./src/articles/ - -echo "[test] SECTION - DETERMINE DATE" - -for i in *.md; do - - echo "[test] reading: $i" - - filename=$( echo "$i" | rev | cut -c4- | rev ) - - if [ "$filename" != "index" ]; then - - export WEBMETA_DATE="" - - if [ -e "$filename.meta" ]; then - echo "[test] running script: $filename.meta" - source ./"$filename".meta - fi - - if [ "$WEBMETA_DATE" == "" ]; then - export WEBMETA_DATE="2001-09-11*" - fi - - articlearr["$filename"]="$WEBMETA_DATE" - - fi - -done - -echo "[test] SECTION - SORT" - -workingarr=($( sort -nr < <(printf '%s\n' "${articlearr[@]}") )) - -for date in "${workingarr[@]}"; do - - for key in "${!articlearr[@]}"; do - if [ "${articlearr[$key]}" == "$date" ]; then - echo "$date matches $key" - thebestarr["$date"]="$key" - fi - done - -done - -echo "[test] SECTION - GENERATE" - -# ... - diff --git a/src/articles/allerersterartikel.md b/src/articles/allerersterartikel.md new file mode 100644 index 0000000..7898192 --- /dev/null +++ b/src/articles/allerersterartikel.md @@ -0,0 +1 @@ +a diff --git a/src/articles/allerersterartikel.meta b/src/articles/allerersterartikel.meta new file mode 100644 index 0000000..b6c3e7e --- /dev/null +++ b/src/articles/allerersterartikel.meta @@ -0,0 +1 @@ +export WEBMETA_DATE="1990-07-28" diff --git a/src/articles/besterartikel.md b/src/articles/besterartikel.md new file mode 100644 index 0000000..6178079 --- /dev/null +++ b/src/articles/besterartikel.md @@ -0,0 +1 @@ +b diff --git a/src/articles/besterartikel.meta b/src/articles/besterartikel.meta new file mode 100644 index 0000000..2885fe7 --- /dev/null +++ b/src/articles/besterartikel.meta @@ -0,0 +1 @@ +export WEBMETA_DATE="1988-07-28" diff --git a/src/articles/lol.md b/src/articles/lol.md new file mode 100644 index 0000000..fc1585b --- /dev/null +++ b/src/articles/lol.md @@ -0,0 +1 @@ +ajksnd diff --git a/src/articles/lol.meta b/src/articles/lol.meta new file mode 100644 index 0000000..4b472f3 --- /dev/null +++ b/src/articles/lol.meta @@ -0,0 +1 @@ +export WEBMETA_DATE="2024-07-28" diff --git a/src/articles/zefinivderletzteartikel.md b/src/articles/zefinivderletzteartikel.md new file mode 100644 index 0000000..b680253 --- /dev/null +++ b/src/articles/zefinivderletzteartikel.md @@ -0,0 +1 @@ +z diff --git a/src/articles/zefinivderletzteartikel.meta b/src/articles/zefinivderletzteartikel.meta new file mode 100644 index 0000000..83c5df5 --- /dev/null +++ b/src/articles/zefinivderletzteartikel.meta @@ -0,0 +1 @@ +export WEBMETA_DATE="2030-07-28" -- cgit v1.2.3