diff options
1 files changed, 80 insertions, 55 deletions
| -rwxr-xr-x | generate.sh | 135 |
diff --git a/generate.sh b/generate.sh index 43023af..0bc2b5c 100755 --- a/generate.sh +++ b/generate.sh @@ -1,64 +1,89 @@ -#!/bin/bash +#!/bin/sh -: ${REPO_FOLDER:=.} -: ${GEN_FOLDER:=./website} -: ${GEN_TINY_FOLDER:=./website.tiny} -: ${AWK_FOLDER:=./awk-edits} +set -e -# 0 Fix hardlinks {{{ - while read -r folder - do - if [ -f "$folder.md" ] && [ ! "$folder.md" -ef "$folder/index.md" ] - then - rm "$folder/index.md" >/dev/null 2>&1 - ln "$folder.md" "$folder/index.md" - fi - done << EOF -$(find "$REPO_FOLDER/src" -maxdepth 1 -type d) -EOF - if [ ! "src/favicon.ico" -ef "src/img/favicon.ico" ] +: ${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 + +#== 0. Check for changes ==# + +if [ -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 ==# + +while read -r folder +do + if [ -f "$folder.du" ] && [ ! "$folder.du" -ef "$folder/index.du" ] then - rm "src/favicon.ico" >/dev/null 2>&1 - ln "src/img/favicon.ico" "src/favicon.ico" + rm "$folder/index.du" >/dev/null 2>&1 + ln "$folder.du" "$folder/index.du" fi - echo "[Stage 0] Fixed folder/index.md hardlinks" -# }}} -# 1. Markdown source to HTML {{{ - [ $# -eq 0 -a "$(id -u -n)" != "www-data" ] && echo "[Warning] Running in \"production\" by a user that isn't www-root!" - - [ ! -d "$GEN_FOLDER" ] && mkdir "$GEN_FOLDER" - [ $# -eq 0 -a "$(stat -c %U "$GEN_FOLDER")" != "www-data" ] && echo "[Warning] Running in \"production\" while $GEN_FOLDER isn't owned by www-data!" - - /usr/bin/env dash ./csg/csg "$REPO_FOLDER/src" "$GEN_FOLDER" '& \\— Syndamia' 'https://syndamia.com' "$AWK_FOLDER" -# }}} -# 2. Tiny version, strip away styles and other stuff {{{ - [ ! -d "$GEN_TINY_FOLDER" ] && mkdir "$GEN_TINY_FOLDER" - [ $# -eq 0 -a "$(stat -c %U "$GEN_TINY_FOLDER")" != "www-data" ] && echo "[Warning] Running in \"production\" while $GEN_TINY_FOLDER isn't owned by www-data!" +done << EOF +$(find "$SRC" -maxdepth 1 -type d) +EOF - # Just take what is already made, no need to regenerate everything - cp -r "$GEN_FOLDER"/* "$GEN_TINY_FOLDER" +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 - # Remove unnecessary files - rm -f "$GEN_TINY_FOLDER"/*.css - rm -rf "$GEN_TINY_FOLDER"/fonts/ - rm -f "$GEN_TINY_FOLDER"/.files +echo "[1/4] Fixed folder/index.md hardlinks" - improveForTINY() { - for file in $(find "$GEN_TINY_FOLDER" -type f -name "*.html"); do - # Remove references to stylesheets in all files - sed -i -E 's/^.*(rel="stylesheet|\<script|btn).*//g' $file - sed -i 's/<span>Content/<br><span>Content/g' $file - # Fix svg images being too big (scaling without limit) - sed -i 's/<\/head>/\t<style>img[src$="svg"] { max-height: 1em; } #index-contents-img { max-width: 7.6em; }<\/style>\n<\/head>/' $file - done - } +#== 2. Dunbar source to HTML ==# - echo "[Stage 3] Tiny website" - if [ $# -eq 0 ]; then - improveForTINY +mkdir -p "$DST" +cp -a "$SRC/." "$DST" - - else - improveForTINY - fi -# }}} +/bin/sh ./dunbar/dunbar_awk/dunbar.sh html \ + -i \ + -e ./ext/pagenav.awk -e ./ext/presentation.awk \ + ./ext/global.du \ + $(find "$DST" -type f -name "*.du") + +echo "[2/4] Converted '$SRC' to dunbar in '$DST'" + +#== 3. Meta handling ==# + +$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" + +#== 4. Tiny version, strip away styles and other stuff ==# + +mkdir -p "$DST.tiny" +cp -a "$DST/." "$DST.tiny" +rm -rf "$DST.tiny"/*.css "$DST.tiny"/fonts/ + +$AWK ' + !/rel="stylesheet"/ && !/<script/ && !/class="btn/ { + print > FILENAME + } +' \ +$(find "$DST.tiny" -type f -name "*.html") + +echo "[4/4] Created tiny website in '$DST.tiny'" |