sebastiano.tronto.net

Source files and build scripts for my personal website
git clone https://git.tronto.net/sebastiano.tronto.net
Download | Log | Files | Refs | README

build.sh (3312B)


      1 #!/bin/sh
      2 
      3 basedir="$(pwd)"
      4 
      5 recursivebuild() {
      6 	local destdir=$(echo "$1" | sed 's|^src|http|')
      7 	mkdir -p "$destdir"
      8 	for file in "$1"/*; do
      9 		if [ -d "$file" ]; then
     10 			mkdir -p "$destdir/$(basename "$file")"
     11 			recursivebuild "$file"
     12 		else
     13 			copyfile "$file" "$destdir"
     14 		fi
     15 	done
     16 }
     17 
     18 # This function is currently useless, but we keep it in case we need to
     19 # preprocess some m4 files.
     20 mdpreprocess() {
     21 	file="$1"
     22 	if [ "$(echo "$file" | sed 's/.*\.//')" = "m4" ]; then
     23 		printf 'm4_include(macros.m4)m4_dnl\n%s\n' "$(cat "$file")" | \
     24 			m4 -P -I "$basedir/utils"
     25 	else
     26 		cat "$file"
     27 	fi
     28 }
     29 
     30 copyfile() {
     31 	file=$1
     32 	dest=$2
     33 	ind=$dest/index.html
     34 	extension=$(echo "$file" | sed 's/.*\.//')
     35 	case "$extension" in
     36 	# m4 preprocess is currently disabled
     37 	#m4)
     38 	#	noext=$(echo "$file" | sed 's/\..*//')
     39 	#	mdpreprocess "$file" > $noext.md
     40 	#	;;
     41 	md)
     42 		t="$(markdowntitle "$file")"
     43 		sed "s/TITLE/$t/" < top.html > "$ind"
     44 		mdpreprocess "$file" | \
     45 			lowdown --html-no-skiphtml --html-no-escapehtml \
     46 			>> "$ind"
     47 		cat bottom.html >> "$ind"
     48 		;;
     49 	noheadermd)
     50 		t="$(markdowntitle "$file")"
     51 		sed "s/TITLE/$t/" < top-nobar.html > "$ind"
     52 		mdpreprocess "$file" | \
     53 			lowdown --html-no-skiphtml --html-no-escapehtml \
     54 			>> "$ind"
     55 		;;
     56 	html)
     57 		t="$(htmltitle "$file")"
     58 		cat top.html "$file" bottom.html | sed "s/TITLE/$t/" > "$ind"
     59 		;;
     60 	raw)
     61 		namenoraw="$(basename "$file" | sed 's/\.raw$//')"
     62 		cp "$file" "$dest/$namenoraw"
     63 		;;
     64 	*)
     65 		cp "$file" "$dest/$(basename "$file")"
     66 	esac
     67 }
     68 
     69 markdowntitle() {
     70 	grep '^# ' "$1" | head -n 1 | sed 's/^# //'
     71 }
     72 
     73 htmltitle() {
     74 	grep '<!--TITLE: ' "$1" | sed 's/^<!--TITLE: //' | sed 's/-->$//'
     75 }
     76 
     77 makeblogindexandfeed() {
     78 	mkdir -p http/blog
     79 	bf=http/blog/index.html
     80 	ff=http/blog/feed.xml
     81 
     82 	sed "s/TITLE/Blog/" < top.html > "$bf"
     83 	{ echo '<h1 id="blog">Blog</h1>';
     84 	  echo '<table id="blog">';
     85 	  echo '<a href="../series">Blog series</a> - ';
     86 	  echo '<a href="feed.xml">RSS feed</a>'; } >> "$bf"
     87 
     88 	cp feed-top.xml "$ff"
     89 
     90 	for i in $(ls src/blog | sort -r); do
     91 		[ -d "src/blog/$i" ] || continue
     92 
     93 		f="src/blog/$i/*.md"
     94 		d="$(echo "$i" | grep -oE '^[0-9]{4}-[0-9]{2}-[0-9]{2}')"
     95 		t="$(markdowntitle $f)"
     96 		link="https://sebastiano.tronto.net/blog/$i"
     97 
     98 		thisyear="$(echo "$d" | sed 's/-.*//')"
     99 		if [ "$thisyear" != "$lastyear" ]; then
    100 			echo "<tr><td><h2>$thisyear</h2></td></tr>" >> "$bf"
    101 			lastyear=$thisyear
    102 		fi
    103 
    104 		{ echo "<tr><td>$d</td>";
    105 		  echo "<td><a href=\"$i\">$t</a></td></tr>"; } >> "$bf"
    106 
    107 		dd="$(echo "$d" | sed 's/.*-//')"
    108 		mm="$(echo "$d" | sed 's/....-//' | sed 's/-.*//')"
    109 		mon="$(month "$mm")"
    110 		{ echo "<item>";
    111 		  echo "<title>$t</title>";
    112 		  echo "<link>$link</link>";
    113 		  echo "<guid isPermaLink=\"true\">$link</guid>";
    114 		  echo "<description>$t</description>";
    115 		  echo "<pubDate>$dd $mon $thisyear 00:00:00 GMT</pubDate>";
    116 		  echo "</item>";
    117 		  echo ""; } >> $ff
    118 	done
    119 
    120 	echo '</table>' >> "$bf"
    121 	cat bottom.html >> "$bf"
    122 
    123 	{ echo ""; echo "</channel>"; echo "</rss>"; } >> "$ff"
    124 }
    125 
    126 month() {
    127 	case "$1" in
    128 	01)
    129 		echo "Jan"
    130 		;;
    131 	02)
    132 		echo "Feb"
    133 		;;
    134 	03)
    135 		echo "Mar"
    136 		;;
    137 	04)
    138 		echo "Apr"
    139 		;;
    140 	05)
    141 		echo "May"
    142 		;;
    143 	06)
    144 		echo "Jun"
    145 		;;
    146 	07)
    147 		echo "Jul"
    148 		;;
    149 	08)
    150 		echo "Aug"
    151 		;;
    152 	09)
    153 		echo "Sep"
    154 		;;
    155 	10)
    156 		echo "Oct"
    157 		;;
    158 	11)
    159 		echo "Nov"
    160 		;;
    161 	12)
    162 		echo "Dec"
    163 		;;
    164 	esac
    165 }
    166 
    167 makeblogindexandfeed
    168 recursivebuild src