saitti

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.inz.fi/saitti
Log | Files | Refs

commit 25a90afcd7d0c4c3f272f310b57b6d0f174125c1
Author: Santtu Lakkala <inz@inz.fi>
Date:   Sat, 19 Feb 2022 17:42:48 +0200

Initial import

Diffstat:
Asaitti | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+), 0 deletions(-)

diff --git a/saitti b/saitti @@ -0,0 +1,99 @@ +#!/bin/sh + +TMPDIR=$(mktemp -d) +trap 'rm -Rf "$TMPDIR"' EXIT + +html2gph() { + TMP="$(mktemp $TMPDIR/h2g.XXXXXX)" + mv "$TMP" "$TMP.html" + cat >"$TMP.html" + lynx -width 78 -dump "$TMP.html" | lynx2gph file://"$TMP".html + rm "$TMP.html" +} + +applytemplate() +{ + TEMPLATE="$1" + EXT="$2" + eval "cat <<___EOF___ +$(git show HEAD:templates/$TEMPLATE.$EXT/header.$EXT 2>/dev/null | sed -e 's/\$/\\$/g' -e 's/{\([^}]*}\)}/$\1/g') +___EOF___" + cat + eval "cat <<___EOF___ +$(git show HEAD:templates/$TEMPLATE.$EXT/footer.$EXT 2>/dev/null | sed -e 's/\$/\\$/g' -e 's/{\([^}]*}\)}/$\1/g') +___EOF___" +} + +git show HEAD:config.ini >"$TMPDIR/config.ini" +while IFS='=' read key val; do + export $key=$val +done <"$TMPDIR/config.ini" + +test -z "$output_html" && exit 1 +test -z "$output_gopher" && exit 1 + +mkdir -p "$output_html" +mkdir -p "$output_gopher" + +exec 3> "$TMPDIR/index.md" + +echo "## Pages" >&3 +git ls-tree -r HEAD pages/ | while read mode type hash fn; do + date="$(date -d "$(git log --pretty="%cI" HEAD -- $fn | tail -n1)" +%Y-%m-%d)" + case "$mode" in + 040000) + continue + ;; + 120000) + export post_title="$(basename "$fn")" + link="$(git show "$hash")" + ;; + *) + export post_title="$(git show $hash | head -n1 | sed -e 's/^#*\s*//; s/\s*#*\s*$//')" + export date_created="$(date -d "$c" +%Y-%m-%d)" + export date_modified="$(date -d "$e" +%Y-%m-%d)" + hfn="$(echo $fn|sed -e 's/\.md$/.html/')" + gfn="$(echo $fn|sed -e 's/\.md$/.gph/')" + link="$hfn" + + mkdir -p "$output_html/$(dirname "$fn")" + mkdir -p "$output_gopher/$(dirname "$fn")" + echo "$fn" | grep -q '^pages/[^/]*\(/index.md\|\)$' || continue + + git show $hash | smu | applytemplate page html > "$output_html/$hfn" + git show $hash | smu | html2gph | applytemplate page gph < "$output_html/$hfn" > "$output_gopher/$gfn" + esac + + echo "* [$post_title]($link)" >&3 +done + +echo "## Blog" >&3 +git ls-tree HEAD posts/ | awk '$2 == "blob" { print }' | while read mode type hash fn; do + git log --pretty="%aI" HEAD -- $fn | awk '!f { f = $0 } { l = $0 } END { printf("%s %s ", f, l) }' + echo $hash $fn +done | sort -r | while read c e hash fn; do + export post_title="$(git show $hash | head -n1 | sed -e 's/^#*\s*//; s/\s*#*\s*$//')" + export date_created="$(date -d "$c" +%Y-%m-%d)" + export date_modified="$(date -d "$e" +%Y-%m-%d)" + hfn="$(echo $fn|sed -e 's/\.md$/.html/')" + gfn="$(echo $fn|sed -e 's/\.md$/.gph/')" + mkdir -p "$output_html/$(dirname "$fn")" + mkdir -p "$output_gopher/$(dirname "$fn")" + echo -n "* $date_created [$post_title]($hfn)" >&3 + test "$date_created" = "$date_modified" || echo -n " (updated $date_modified)" >&3 + echo >&3 + git show $hash | smu | applytemplate post html > "$output_html/$hfn" + git show $hash | smu | html2gph | applytemplate post gph > "$output_gopher/$gfn" +done + +exec 3<&- + +smu < "$TMPDIR/index.md" | applytemplate index html > "$output_html/index.html" +smu < "$TMPDIR/index.md" | html2gph | applytemplate index gph > "$output_gopher/index.gph" +( + eval "cat <<___EOF___ +$(git show HEAD:templates/index.gph/header.gph) +___EOF___" + smu < "$TMPDIR/index.md" | html2gph + git show HEAD:templates/index.html/footer.html +) > "$output_gopher/index.gph"