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


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