Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit4c5629df62c0a694b6ef3aada2ec86890bfeceaa (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-09-12 14:11:59 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-09-12 14:16:18 +0300
Files06b3445303b7139a580ac54e90100861ca4d5532
syndamia.com-4c5629df62c0a694b6ef3aada2ec86890bfeceaa.tar
syndamia.com-4c5629df62c0a694b6ef3aada2ec86890bfeceaa.tar.gz
syndamia.com-4c5629df62c0a694b6ef3aada2ec86890bfeceaa.zip
Parent6b8cae12cb5d60b37931332d9d8008649ae14566 (diff)
feat!: Rework website generation
- Move src.du into src/INIT.du - Replace generate.sh with make.sh, which uses multiple stages for execution and allows customising them. - Added a stage for sitemap generation in make.sh
4 files changed, 149 insertions, 156 deletions
-rwxr-xr-xgenerate.sh138
-rwxr-xr-xmake.sh149
-rw-r--r--meta/meta.awk18
-rw-r--r--src/INIT.du (renamed from src.du)0
diff --git a/generate.sh b/generate.sh
deleted file mode 100755
index da4a600..0000000
--- a/generate.sh
+++ /dev/null
@@ -1,138 +0,0 @@
-#!/bin/sh
-
-set -e
-
-: ${SRC:=$PWD/src}
-: ${DST:=./website}
-: ${URL:=https://syndamia.com}
-: ${AWK:="mawk"}
-
-: ${HEADER:=$PWD/meta/header.html}
-: ${FOOTER:=$PWD/meta/footer.html}
-: ${META:=$PWD/meta/meta.tsv}
-
-export SRC DST URL AWK HEADER FOOTER META
-
-NO_FIX=
-NO_META=
-NO_TINY=
-FORCE_GEN=
-HIGHLIGHT=
-while [ -n "$1" ]
-do
- case "$1" in
- (-x|--no_fix) NO_FIX=y ;;
- (-m|--no_meta) NO_META=y ;;
- (-t|--no_tiny) NO_TINY=y ;;
- (-f|--force) FORCE_GEN=y ;;
- (-hi|--highlight)
- if command -v highlight >/dev/null 2>&1
- then
- HIGHLIGHT="$(command -v highlight)"
- else
- echo 'Requested highlighting but could not find "highlight" command!'
- exit 1
- fi
- ;;
- (*) echo "Unknown argument '$1'!" ; exit 1 ;;
- esac
- shift
-done
-
-export HIGHLIGHT
-
-#== 0. Check for changes ==#
-
-if [ -z "$FORCE_GEN" ] \
- && [ -d "$DST" ] \
- && [ -f "$DST/.commit" ] \
- && command -v git >/dev/null 2>&1 \
- && [ -z "$(git status -s)" ] \
- && [ "$(cat "$DST"/.commit)" = "$(git rev-parse HEAD)" ]
-then
- echo "Output '$DST' is up to date with website source '$SRC'!"
- echo "Refusing to generate..."
- exit 0
-fi
-
-#== 1. Fix hardlinks ==#
-
-if [ -z "$NO_FIX" ]
-then
- while read -r folder
- do
- if [ -f "$folder.du" ] && [ ! "$folder.du" -ef "$folder/index.du" ]
- then
- rm "$folder/index.du" >/dev/null 2>&1
- ln "$folder.du" "$folder/index.du"
- fi
- done << EOF
-$(find "$SRC" -maxdepth 1 -type d)
-EOF
-
- if [ ! "src/favicon.ico" -ef "src/img/favicon.ico" ]
- then
- rm "src/favicon.ico" >/dev/null 2>&1
- ln "src/img/favicon.ico" "src/favicon.ico"
- fi
-
- echo "[1/4] Fixed folder/index.md hardlinks"
-else
- echo "[1/4] Skipping..."
-fi
-
-#== 2. Dunbar source to HTML ==#
-
-mkdir -p "$DST"
-rm -r "$DST"/* 2>/dev/null || true
-cp -a "$SRC/." "$DST"
-
-OUTPUT_FORMAT=HTML $AWK \
- -f ./dunbar/dunbar_awk/dunbar.awk \
- ./dunbar/stdenv/sgml.du \
- -c --ignore-errors \
- ./src.du \
- $(find "$DST" -type f -name "*.du")
-
-date '+%e.%m.%Y %H:%M:%S %Z' > "$DST"/.build
-
-echo "[2/4] Converted '$SRC' to dunbar in '$DST'"
-
-#== 3. Meta handling ==#
-
-if [ -z "$NO_META" ]
-then
- $AWK -f ./meta/meta.awk \
- -v date="$(date +%Y-%m-%d)" \
- $(find "$DST" -type f -name "*.html")
-
- if command -v git >/dev/null 2>&1
- then
- git rev-parse HEAD > "$DST"/.commit
- fi
-
- echo "[3/4] Added HTML header/footer, generated sitemap"
-else
- echo "[3/4] Skipping"
-fi
-
-#== 4. Tiny version, strip away styles and other stuff ==#
-
-if [ -z "$NO_TINY" ]
-then
- mkdir -p "$DST.tiny"
- rm -r "$DST.tiny"/* 2>/dev/null || true
- cp -a "$DST/." "$DST.tiny"
- rm -rf "$DST.tiny"/*.css "$DST.tiny"/fonts/
-
- sed -i \
- -e '/rel="stylesheet"/d' \
- -e '/<script/d' \
- -e '/id="settingsWrapper"/,/<\/nav>/d' \
- -e '/id="scrollBtn"/d' \
- $(find "$DST.tiny" -type f -name "*.html")
-
- echo "[4/4] Created tiny website in '$DST.tiny'"
-else
- echo "[4/4] Skipping..."
-fi
diff --git a/make.sh b/make.sh
new file mode 100755
index 0000000..2437873
--- /dev/null
+++ b/make.sh
@@ -0,0 +1,149 @@
+#!/bin/sh
+
+set -e -a
+
+: ${SRC:=$PWD/src}
+: ${DST:=./website}
+: ${URL:=https://syndamia.com}
+: ${AWK:="mawk"}
+
+condition() {
+ if [ -z "$FORCE_GEN" ] \
+ && [ -d "$DST" ] \
+ && [ -f "$DST/.commit" ] \
+ && command -v git >/dev/null 2>&1 \
+ && [ -z "$(git status -s)" ] \
+ && [ "$(cat "$DST"/.commit)" = "$(git rev-parse HEAD)" ]
+ then
+ echo "Output '$DST' is up to date with website source '$SRC'!"
+ exit 0
+ fi
+}
+
+patch() {
+ while read -r folder
+ do
+ if [ -f "$folder.du" ] && [ ! "$folder.du" -ef "$folder/index.du" ]
+ then
+ rm "$folder/index.du" >/dev/null 2>&1
+ ln "$folder.du" "$folder/index.du"
+ fi
+ done << EOF
+$(find "$SRC" -maxdepth 1 -type d)
+EOF
+
+ if [ ! "src/favicon.ico" -ef "src/img/favicon.ico" ]
+ then
+ rm "src/favicon.ico" >/dev/null 2>&1
+ ln "src/img/favicon.ico" "src/favicon.ico"
+ fi
+}
+
+prepare() {
+ mkdir -p "$DST"
+ rm -r "$DST"/* 2>/dev/null || true
+ cp -a "$SRC/." "$DST"
+ rm "$DST/INIT.du"
+}
+
+build() {
+ OUTPUT_FORMAT=HTML "$AWK" \
+ -f ./dunbar/dunbar_awk/dunbar.awk \
+ ./dunbar/stdenv/sgml.du \
+ -c "$SRC/INIT.du" \
+ $(find "$DST" -type f -name '*.du')
+
+ date '+%e.%m.%Y %H:%M:%S %Z' > "$DST"/.build
+
+ if command -v git >/dev/null 2>&1
+ then
+ git rev-parse HEAD > "$DST"/.commit
+ fi
+}
+
+build_sitemap() {
+ cat <<SITEMAP >"$DST"/sitemap.xml
+<?xml version="1.0" encoding="UTF-8"?>
+<urlset
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
+ http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
+ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+$("$AWK" -v date="$(date +%Y-%m-%d)" '
+ {
+ URL = ENVIRON["URL"] substr($0, length(ENVIRON["DST"]) + 1)
+ print "<url><loc>" URL "</loc><lastmod>" date "</lastmod><priority>1.0</priority></url>"
+ }
+' <<FILES
+$(find "$DST" -type f -name '*.html')
+FILES
+)
+</urlset>
+SITEMAP
+}
+
+build_tiny() {
+ mkdir -p "$DST.tiny"
+ rm -r "$DST.tiny"/* 2>/dev/null || true
+ cp -a "$DST/." "$DST.tiny"
+ rm -rf "$DST.tiny"/*.css "$DST.tiny"/fonts/
+
+ sed -i \
+ -e '/rel="stylesheet"/d' \
+ -e '/<script/d' \
+ -e '/id="settingsWrapper"/,/<\/nav>/d' \
+ -e '/id="scrollBtn"/d' \
+ $(find "$DST.tiny" -type f -name "*.html")
+}
+
+fixup_local() {
+ while read -r f
+ do
+ root="$(echo "$f" | sed 's|^./website\(.*\)/.*.html$|./\1/|g;s|[^/.]\+|..|g;s|//|/|g;s|\.\.\.\+|..|g')"
+ sed -i 's \(\(href\|src\)="[^"]*/[^"./]*\)" \1/index.html" g;s \(\(href\|src\)="\)/ \1'"$root"' g;s \(\(href\|src\)="\([^/"][^/"]\|/[^/]\)*[^/"]\?\)/\+ \1/ g' "$f"
+ done <<EOF
+$(find "$DST" -type f -name '*.html')
+EOF
+}
+
+#---#
+
+[ -z "$1" ] && set prod
+
+stages=''
+C=0
+for arg in "$@"
+do
+ case "$arg" in
+ (*=*)
+ eval "$arg"
+ ;;
+ (common)
+ stages="$stages condition patch prepare build"
+ : $((C = C + 4))
+ ;;
+ (local)
+ stages="$stages condition patch prepare build build_sitemap fixup_local"
+ : $((C = C + 6))
+ ;;
+ (prod)
+ stages="$stages condition patch prepare build build_sitemap build_tiny"
+ : $((C = C + 6))
+ ;;
+ (*)
+ stages="$stages $arg"
+ : $((C = C + 1))
+ esac
+done
+
+N=1
+for stage in $stages
+do
+ printf "[%d/%d] %s\n" "$N" "$C" "$stage"
+ if "$stage"
+ then
+ : $((N = N + 1))
+ else
+ exit $?
+ fi
+done
diff --git a/meta/meta.awk b/meta/meta.awk
deleted file mode 100644
index e439fc4..0000000
--- a/meta/meta.awk
+++ /dev/null
@@ -1,18 +0,0 @@
-BEGIN {
- sitemap = ENVIRON["DST"] "/sitemap.xml"
- print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ORS \
- "<urlset" ORS \
- "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" ORS \
- "xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9" ORS \
- "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"" ORS \
- "xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">" > sitemap
-
- for (i = ARGC; i > 0; --i) {
- if (!ARGV[i]) continue
-
- #-- Add to sitemap --#
- print "<url><loc>" ENVIRON["URL"] substr(ARGV[i], length(ENVIRON["DST"]) + 1) "</loc><lastmod>" date "</lastmod><priority>1.0</priority></url>" > sitemap
- }
-
- print "</urlset>" > sitemap
-}
diff --git a/src.du b/src/INIT.du
index 717f259..717f259 100644
--- a/src.du
+++ b/src/INIT.du