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 (2651B)


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