saitti (3215B)
1 #!/bin/sh 2 3 TMPDIR=$(mktemp -d) 4 trap 'rm -Rf "$TMPDIR"' EXIT 5 6 html2gph() { 7 TMP="$(mktemp $TMPDIR/h2g.XXXXXX)" 8 mv "$TMP" "$TMP.html" 9 cat >"$TMP.html" 10 lynx -width 78 -dump "$TMP.html" | lynx2gph file://"$TMP".html 11 rm "$TMP.html" 12 } 13 14 applytemplate() 15 { 16 TEMPLATE="$1" 17 EXT="$2" 18 eval "cat <<___EOF___ 19 $(git show HEAD:templates/$TEMPLATE.$EXT/header.$EXT 2>/dev/null | sed -e 's/\$/\\$/g' -e 's/{\([^}]*}\)}/$\1/g') 20 ___EOF___" 21 cat 22 eval "cat <<___EOF___ 23 $(git show HEAD:templates/$TEMPLATE.$EXT/footer.$EXT 2>/dev/null | sed -e 's/\$/\\$/g' -e 's/{\([^}]*}\)}/$\1/g') 24 ___EOF___" 25 } 26 27 git show HEAD:config.ini >"$TMPDIR/config.ini" 28 while IFS='=' read key val; do 29 export $key=$val 30 done <"$TMPDIR/config.ini" 31 32 test -z "$output_html" && exit 1 33 test -z "$output_gopher" && exit 1 34 35 mkdir -p "$output_html" 36 mkdir -p "$output_gopher" 37 38 exec 3> "$TMPDIR/index.md" 39 40 echo "## Pages" >&3 41 git ls-tree -r HEAD pages/ | while read mode type hash fn; do 42 date="$(date -d "$(git log --pretty="%cI" HEAD -- $fn | tail -n1)" +%Y-%m-%d)" 43 case "$mode" in 44 040000) 45 continue 46 ;; 47 120000) 48 export post_title="$(basename "$fn")" 49 link="$(git show "$hash")" 50 ;; 51 *) 52 export post_title="$(git show $hash | head -n1 | sed -e 's/^#*\s*//; s/\s*#*\s*$//')" 53 export date_created="$(date -d "$c" +%Y-%m-%d)" 54 export date_modified="$(date -d "$e" +%Y-%m-%d)" 55 hfn="$(echo $fn|sed -e 's/\.md$/.html/')" 56 gfn="$(echo $fn|sed -e 's/\.md$/.gph/')" 57 link="$hfn" 58 59 mkdir -p "$output_html/$(dirname "$fn")" 60 mkdir -p "$output_gopher/$(dirname "$fn")" 61 echo "$fn" | grep -q '^pages/[^/]*\(/index.md\|\)$' || continue 62 63 git show $hash | smu | applytemplate page html > "$output_html/$hfn" 64 git show $hash | smu | html2gph | applytemplate page gph < "$output_html/$hfn" > "$output_gopher/$gfn" 65 esac 66 67 echo "* [$post_title]($link)" >&3 68 done 69 70 echo "## Blog" >&3 71 git ls-tree HEAD posts/ | awk '$2 == "blob" { print }' | while read mode type hash fn; do 72 git log --pretty="%aI" HEAD -- $fn | awk '!f { f = $0 } { l = $0 } END { printf("%s %s ", f, l) }' 73 echo $hash $fn 74 done | sort -r | while read c e hash fn; do 75 export post_title="$(git show $hash | head -n1 | sed -e 's/^#*\s*//; s/\s*#*\s*$//')" 76 export date_created="$(date -d "$c" +%Y-%m-%d)" 77 export date_modified="$(date -d "$e" +%Y-%m-%d)" 78 hfn="$(echo $fn|sed -e 's/\.md$/.html/')" 79 gfn="$(echo $fn|sed -e 's/\.md$/.gph/')" 80 mkdir -p "$output_html/$(dirname "$fn")" 81 mkdir -p "$output_gopher/$(dirname "$fn")" 82 echo -n "* $date_created [$post_title]($hfn)" >&3 83 test "$date_created" = "$date_modified" || echo -n " (updated $date_modified)" >&3 84 echo >&3 85 git show $hash | smu | applytemplate post html > "$output_html/$hfn" 86 git show $hash | smu | html2gph | applytemplate post gph > "$output_gopher/$gfn" 87 done 88 89 exec 3<&- 90 91 smu < "$TMPDIR/index.md" | applytemplate index html > "$output_html/index.html" 92 smu < "$TMPDIR/index.md" | html2gph | applytemplate index gph > "$output_gopher/index.gph" 93 ( 94 eval "cat <<___EOF___ 95 $(git show HEAD:templates/index.gph/header.gph) 96 ___EOF___" 97 smu < "$TMPDIR/index.md" | html2gph 98 git show HEAD:templates/index.html/footer.html 99 ) > "$output_gopher/index.gph" 100 101 git archive --format=tar HEAD resources | (cd "$output_html"; tar x)