diff options
| Commit | 40213ad72ebf72298e0eb6c7ded9729c36fd13c8 (patch) | |
|---|---|---|
| Author | 2025-08-19 15:44:36 +0300 | |
| Committer | 2025-08-19 15:44:41 +0300 | |
| Files | ba57b6eddc12396e2a5408daca46c2fc4a856584 | |
| syndamia.com-40213ad72ebf72298e0eb6c7ded9729c36fd13c8.tar syndamia.com-40213ad72ebf72298e0eb6c7ded9729c36fd13c8.tar.gz syndamia.com-40213ad72ebf72298e0eb6c7ded9729c36fd13c8.zip | ||
| Parent | 6969ff774c8d5831850ef3afa72b1956767dc18b (diff) | |
feat(generate.sh): Improve implementation and add tiny website generation
2 files changed, 61 insertions, 38 deletions
| -rwxr-xr-x | generate.sh | 93 | ||||
| -rw-r--r-- | meta/meta.awk | 6 |
diff --git a/generate.sh b/generate.sh index 6d92ce0..2e9fd70 100755 --- a/generate.sh +++ b/generate.sh @@ -1,46 +1,69 @@ -#!/bin/bash +#!/bin/sh : ${SRC:=$PWD/src} -: ${GEN_DIR:=./website} +: ${DST:=./website} : ${URL:=https://syndamia.com} +: ${AWK:="mawk"} + : ${HEADER:=$PWD/meta/header.html} : ${FOOTER:=$PWD/meta/footer.html} : ${META:=$PWD/meta/meta.tsv} -# 0 Fix hardlinks {{{ - 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" ] +export SRC DST URL AWK HEADER FOOTER META + +#== 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. Dunbar source to HTML {{{ - mkdir -p "$GEN_DIR" - cp -a "$SRC/." "$GEN_DIR" +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" + +#== 2. Dunbar source to HTML ==# + +mkdir -p "$DST" +cp -a "$SRC/." "$DST" + +/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") + +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="mawk" - export HEADER FOOTER META GEN_DIR AWK URL +$AWK ' + !/rel="stylesheet"/ && !/<script/ && !/class="btn/ { + print > FILENAME + } +' \ +$(find "$DST.tiny" -type f -name "*.html") - /usr/bin/env dash ./dunbar/dunbar_awk/dunbar.sh html \ - -i \ - -e ./ext/pagenav.awk -e ./ext/presentation.awk \ - ./ext/global.du \ - $(find "$GEN_DIR" -type f -name "*.du") -# }}} -# 2. Meta handling {{{ - mawk -f ./meta/meta.awk -v date="$(date +%Y-%m-%d)" $(find "$GEN_DIR" -type f -name "*.html") -# }}} -# 2. Tiny version, strip away styles and other stuff {{{ - # TODO -# }}} +echo "[4/4] Created tiny website in '$DST.tiny'" diff --git a/meta/meta.awk b/meta/meta.awk index 7688d6a..f586fef 100644 --- a/meta/meta.awk +++ b/meta/meta.awk @@ -10,7 +10,7 @@ BEGIN { HEADER = getfile(ENVIRON["HEADER"]) FOOTER = getfile(ENVIRON["FOOTER"]) - sitemap = ENVIRON["GEN_DIR"] "/sitemap.xml" + 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 \ @@ -23,14 +23,14 @@ BEGIN { #-- Add header and footer --# start = HEADER - FILENAME = substr(ARGV[i], length(ENVIRON["GEN_DIR"]) + 2) + FILENAME = substr(ARGV[i], length(ENVIRON["DST"]) + 2) gsub(/\$TITLE/, meta_title[FILENAME], start) gsub(/\$DESCRIPTION/, meta_description[FILENAME], start) print start getfile(ARGV[i]) FOOTER > ARGV[i] #-- Add to sitemap --# - print "<url><loc>" ENVIRON["URL"] substr(ARGV[i], length(ENVIRON["GEN_DIR"]) + 1) "</loc><lastmod>" date "</lastmod><priority>1.0</priority></url>" > 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 |