#!/bin/sh basedir="$(pwd)" bottomtmp="$(mktemp)" recursivebuild() { local destdir=$(echo "$1" | sed 's|^src|http|') mkdir -p "$destdir" for file in "$1"/*; do if [ -d "$file" ]; then mkdir -p "$destdir/$(basename "$file")" recursivebuild "$file" else copyfile "$file" "$destdir" fi done } # This function is currently useless, but we keep it in case we need to # preprocess some m4 files. mdpreprocess() { file="$1" if [ "$(echo "$file" | sed 's/.*\.//')" = "m4" ]; then printf 'm4_include(macros.m4)m4_dnl\n%s\n' "$(cat "$file")" | \ m4 -P -I "$basedir/utils" else cat "$file" fi } copyfile() { file=$1 dest=$2 ind=$dest/index.html extension=$(echo "$file" | sed 's/.*\.//') case "$extension" in # m4 preprocess is currently disabled #m4) # noext=$(echo "$file" | sed 's/\..*//') # mdpreprocess "$file" > $noext.md # ;; md) t="$(markdowntitle "$file")" sed "s/TITLE/$t/" < top.html > "$ind" mdpreprocess "$file" | \ lowdown --html-no-skiphtml --html-no-escapehtml \ >> "$ind" cat "$bottomtmp" >> "$ind" ;; noheadermd) t="$(markdowntitle "$file")" sed "s/TITLE/$t/" < top-nobar.html > "$ind" mdpreprocess "$file" | \ lowdown --html-no-skiphtml --html-no-escapehtml \ >> "$ind" ;; html) t="$(htmltitle "$file")" cat top.html "$file" "$bottomtmp" | sed "s/TITLE/$t/" > "$ind" ;; raw) namenoraw="$(basename "$file" | sed 's/\.raw$//')" cp "$file" "$dest/$namenoraw" ;; *) cp "$file" "$dest/$(basename "$file")" esac } markdowntitle() { grep '^# ' "$1" | head -n 1 | sed 's/^# //' } htmltitle() { grep '$//' } makeblogindexandfeed() { mkdir -p http/blog bf=http/blog/index.html ff=http/blog/feed.xml sed "s/TITLE/Blog/" < top.html > "$bf" { echo '

Blog

'; echo ''; echo 'Blog series - '; echo 'RSS feed'; } >> "$bf" cp feed-top.xml "$ff" for i in $(ls src/blog | sort -r); do [ -d "src/blog/$i" ] || continue f="src/blog/$i/*.md" d="$(echo "$i" | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}')" t="$(markdowntitle $f)" link="https://sebastiano.tronto.net/blog/$i" thisyear="$(echo "$d" | sed 's/-.*//')" if [ "$thisyear" != "$lastyear" ]; then echo "" >> "$bf" lastyear=$thisyear fi { echo ""; echo ""; } >> "$bf" dd="$(echo "$d" | sed 's/.*-//')" mm="$(echo "$d" | sed 's/....-//' | sed 's/-.*//')" mon="$(month "$mm")" { echo ""; echo "$t"; echo "$link"; echo "$link"; echo "$t"; echo "$dd $mon $thisyear 00:00:00 GMT"; echo ""; echo ""; } >> $ff done echo '

$thisyear

$d$t
' >> "$bf" cat "$bottomtmp" >> "$bf" { echo ""; echo ""; echo ""; } >> "$ff" } month() { case "$1" in 01) echo "Jan" ;; 02) echo "Feb" ;; 03) echo "Mar" ;; 04) echo "Apr" ;; 05) echo "May" ;; 06) echo "Jun" ;; 07) echo "Jul" ;; 08) echo "Aug" ;; 09) echo "Sep" ;; 10) echo "Oct" ;; 11) echo "Nov" ;; 12) echo "Dec" ;; esac } sed "s/LASTUPDATE/$(date +'%Y-%m-%d')/" "$bottomtmp" makeblogindexandfeed recursivebuild src