Summary Files Commits Branches @commit @diff @stats
path: root / make.sh
diff options
context:
space:
mode:
1 files changed, 149 insertions, 0 deletions
-rwxr-xr-xmake.sh149
diff --git a/make.sh b/make.sh
new file mode 100755
index 0000000..c18af74
--- /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() {
+ "$AWK" \
+ -f ./dunbar/dunbar_awk/dunbar.awk \
+ ./dunbar/stdenv/lang/html.du ./dunbar/stdenv/code.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