commit 73e3ec7054ec4e70648c6cdbe313a39f460e6c92 parent 49ba8ae22e7a5fc557814db60d46ec48b837f841 Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Mon, 6 Apr 2026 19:51:49 +0200 Some attempt at incremental build, but it actually makes it slower It seems that the bottleneck is just looping over all these files... Moreover, we need to remove files that are no longer wanted from the target, so cleaning the target directory is necessary for now. Diffstat:
| A | utils/build-incremental.sh | | | 237 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 237 insertions(+), 0 deletions(-)
diff --git a/utils/build-incremental.sh b/utils/build-incremental.sh @@ -0,0 +1,237 @@ +#!/bin/sh + +basedir="$(pwd)" + +if [ "$(uname)" = "Linux" ]; then + date_last_modified_cmd="stat -c %Y" +else + date_last_modified_cmd="stat -f %m" +fi + +age_top="$($date_last_modified_cmd top.html)" +age_top_nobar="$($date_last_modified_cmd top-nobar.html)" +age_bottom="$($date_last_modified_cmd bottom.html)" + +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/.*\.//') + age_src="$($date_last_modified_cmd "$file")" + + case "$extension" in + # m4 preprocess is currently disabled + #m4) + # noext=$(echo "$file" | sed 's/\..*//') + # mdpreprocess "$file" > $noext.md + # ;; + md) + if [ \( -f "$ind" \) ]; then + age_dst="$($date_last_modified_cmd "$ind")" + if [ \( "$age_dst" -ge "$age_src" \) -a \ + \( "$age_dst" -ge "$age_top" \) -a \ + \( "$age_dst" -ge "$age_bottom" \) ]; then + echo "Skipping "$file" -> "$ind"" + return + fi + fi + + echo "Building "$file" -> "$ind"" + + t="$(markdowntitle "$file")" + sed "s/TITLE/$t/" < top.html > "$ind" + mdpreprocess "$file" | \ + lowdown --html-no-skiphtml --html-no-escapehtml \ + >> "$ind" + cat bottom.html >> "$ind" + ;; + noheadermd) + if [ \( -f "$ind" \) ]; then + age_dst="$($date_last_modified_cmd "$ind")" + if [ \( "$age_dst" -ge "$age_src" \) -a \ + \( "$age_dst" -ge "$age_top_nobar" \) -a \ + \( "$age_dst" -ge "$age_bottom" \) ]; then + echo "Skipping "$file" -> "$ind"" + return + fi + fi + + echo "Building "$file" -> "$ind"" + + t="$(markdowntitle "$file")" + sed "s/TITLE/$t/" < top-nobar.html > "$ind" + mdpreprocess "$file" | \ + lowdown --html-no-skiphtml --html-no-escapehtml \ + >> "$ind" + ;; + html) + if [ \( -f "$ind" \) ]; then + age_dst="$($date_last_modified_cmd "$ind")" + if [ \( "$age_dst" -ge "$age_src" \) -a \ + \( "$age_dst" -ge "$age_top" \) -a \ + \( "$age_dst" -ge "$age_bottom" \) ]; then + echo "Skipping "$file" -> "$ind"" + return + fi + fi + + echo "Copying "$file" -> "$ind"" + + t="$(htmltitle "$file")" + cat top.html "$file" bottom.html | sed "s/TITLE/$t/" > "$ind" + ;; + raw) + namenoraw="$(basename "$file" | sed 's/\.raw$//')" + if [ \( -f "$dest/$namenoraw" \) ]; then + age_dst="$($date_last_modified_cmd "$dest/$namenoraw")" + if [ "$age_dst" -ge "$age_src" ]; then + echo "Skipping "$file" -> "$dest/$namenoraw"" + return + fi + fi + + echo "Copying "$file" -> "$dest/$namenoraw"" + + cp "$file" "$dest/$namenoraw" + ;; + *) + dest_name="$(basename "$file")" + if [ \( -f "$dest/$dest_name" \) ]; then + age_dst="$($date_last_modified_cmd "$dest/$dest_name")" + if [ "$age_dst" -ge "$age_src" ]; then + echo "Skipping "$file" -> "$dest/$dest_name"" + return + fi + fi + + echo "Copying "$file" -> "$dest/$dest_name"" + + cp "$file" "$dest/$dest_name" + esac +} + +markdowntitle() { + grep '^# ' "$1" | head -n 1 | sed 's/^# //' +} + +htmltitle() { + grep '<!--TITLE: ' "$1" | sed 's/^<!--TITLE: //' | sed 's/-->$//' +} + +makeblogindexandfeed() { + mkdir -p http/blog + bf=http/blog/index.html + ff=http/blog/feed.xml + + sed "s/TITLE/Blog/" < top.html > "$bf" + { echo '<h1 id="blog">Blog</h1>'; + echo '<table id="blog">'; + echo '<a href="../series">Blog series</a> - '; + echo '<a href="feed.xml">RSS feed</a>'; } >> "$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 "<tr><td><h2>$thisyear</h2></td></tr>" >> "$bf" + lastyear=$thisyear + fi + + { echo "<tr><td>$d</td>"; + echo "<td><a href=\"$i\">$t</a></td></tr>"; } >> "$bf" + + dd="$(echo "$d" | sed 's/.*-//')" + mm="$(echo "$d" | sed 's/....-//' | sed 's/-.*//')" + mon="$(month "$mm")" + { echo "<item>"; + echo "<title>$t</title>"; + echo "<link>$link</link>"; + echo "<guid isPermaLink=\"true\">$link</guid>"; + echo "<description>$t</description>"; + echo "<pubDate>$dd $mon $thisyear 00:00:00 GMT</pubDate>"; + echo "</item>"; + echo ""; } >> $ff + done + + echo '</table>' >> "$bf" + cat bottom.html >> "$bf" + + { echo ""; echo "</channel>"; echo "</rss>"; } >> "$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 +} + +makeblogindexandfeed +recursivebuild src