git » homepage.git » commit 337ab0b

title & footer tweaks

author Alan Dipert
2025-10-08 04:43:53 UTC
committer Alan Dipert
2025-10-08 04:43:53 UTC
parent 4ea4a2702a347859f2c983555a6b5c83a0892ff5

title & footer tweaks

Makefile +7 -15
tools/buildinfo.sh +35 -0
tpl/head.html +1 -1

diff --git a/Makefile b/Makefile
index 6bae480..40d7346 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ FOOT := tpl/foot.html
 CSS := tpl/style.css
 MD2HTML ?= /usr/bin/cmark-gfm
 CMARK_FLAGS := --to html --extension table --validate-utf8
+BUILDINFO := tools/buildinfo.sh
 DEPLOY_HOST ?= arsien23i2@dreamhost:tailrecursion.com/~alan
 
 MD_FILES := $(shell find $(SRC) -type f -name '*.md' | LC_ALL=C sort)
@@ -21,7 +22,7 @@ $(OUT)/style.css: $(CSS)
 $(OUT):
 	@mkdir -p $(OUT)
 
-$(OUT)/%.html: $(SRC)/%.md $(HEAD) $(FOOT) tools/mdlink2html.awk | $(OUT)
+$(OUT)/%.html: $(SRC)/%.md $(HEAD) $(FOOT) tools/mdlink2html.awk $(BUILDINFO) | $(OUT)
 	@mkdir -p $(@D)
 	@awk -f tools/mdlink2html.awk $< > $@.rewritten.md
 	@if [ ! -x $(MD2HTML) ]; then \
@@ -35,21 +36,12 @@ $(OUT)/%.html: $(SRC)/%.md $(HEAD) $(FOOT) tools/mdlink2html.awk | $(OUT)
 	fi
 	@$(MD2HTML) $(CMARK_FLAGS) $@.rewritten.md > $@.body.html
 	@css_prefix="$$(dirname "$@" | sed -e 's#^$(OUT)##' -e 's#^/##' -e 's#[^/][^/]*#../#g')"; \
-		build_user=$$(whoami); \
-		build_host=$$(hostname); \
-		day=$$(date '+%-d'); \
-		case $$day in 11|12|13) suffix=th ;; *1) suffix=st ;; *2) suffix=nd ;; *3) suffix=rd ;; *) suffix=th ;; esac; \
-		dow=$$(date '+%A'); \
-		month=$$(date '+%B'); \
-		year=$$(date '+%Y'); \
-		time=$$(date '+%-I:%M%p %Z'); \
-		git_sha_short=$$(git rev-parse --short HEAD); \
-		git_sha_full=$$(git rev-parse HEAD); \
-		repo_url="https://tailrecursion.com/git-arr/r/homepage.git/c/$${git_sha_full}/"; \
-		build_info="Built by $$build_user@$$build_host on $$dow, $$month $$day$$suffix $$year at $$time (git <a href=\"$${repo_url}\">$$git_sha_short</a>)"; \
+		page_title=$$(basename "$<" .md); \
+		build_info=$$($(BUILDINFO)); \
 		build_info_esc=$$(printf '%s\n' "$$build_info" | sed 's/[\\/\&]/\\&/g'); \
-		sed -e "s|@CSS@|$${css_prefix}|g" -e "s|@BUILDINFO@|$${build_info_esc}|g" $(HEAD) > $@.head.html; \
-		sed -e "s|@CSS@|$${css_prefix}|g" -e "s|@BUILDINFO@|$${build_info_esc}|g" $(FOOT) > $@.foot.html; \
+		page_title_esc=$$(printf '%s\n' "$$page_title" | sed 's/[\\/\&]/\\&/g'); \
+		sed -e "s|@CSS@|$${css_prefix}|g" -e "s|@BUILDINFO@|$${build_info_esc}|g" -e "s|@TITLE@|$${page_title_esc}|g" $(HEAD) > $@.head.html; \
+		sed -e "s|@CSS@|$${css_prefix}|g" -e "s|@BUILDINFO@|$${build_info_esc}|g" -e "s|@TITLE@|$${page_title_esc}|g" $(FOOT) > $@.foot.html; \
 		cat $@.head.html $@.body.html $@.foot.html > $@; \
 		rm -f $@.head.html $@.foot.html
 	@rm -f $@.rewritten.md $@.body.html
diff --git a/tools/buildinfo.sh b/tools/buildinfo.sh
new file mode 100755
index 0000000..9bac515
--- /dev/null
+++ b/tools/buildinfo.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+ordinal_suffix() {
+  local day="$1"
+  case $day in
+    11|12|13) printf 'th'; return ;;
+  esac
+  case ${day: -1} in
+    1) printf 'st' ;;
+    2) printf 'nd' ;;
+    3) printf 'rd' ;;
+    *) printf 'th' ;;
+  esac
+}
+
+main() {
+  local user host day suffix dow month year time sha_full sha_short repo_url
+  user=$(whoami)
+  host=$(hostname)
+  day=$(date '+%-d')
+  suffix=$(ordinal_suffix "$day")
+  dow=$(date '+%A')
+  month=$(date '+%B')
+  year=$(date '+%Y')
+  time=$(date '+%-I:%M%p %Z')
+  sha_full=$(git rev-parse HEAD)
+  sha_short=$(git rev-parse --short HEAD)
+  repo_url="https://tailrecursion.com/git-arr/r/homepage.git/c/${sha_full}/"
+
+  printf 'Built by %s@%s on %s, %s %s%s %s at %s (git <a href="%s">%s</a>)\n' \
+    "$user" "$host" "$dow" "$month" "$day" "$suffix" "$year" "$time" "$repo_url" "$sha_short"
+}
+
+main "$@"
diff --git a/tpl/head.html b/tpl/head.html
index a83a59b..d7ab577 100644
--- a/tpl/head.html
+++ b/tpl/head.html
@@ -3,7 +3,7 @@
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width,initial-scale=1">
-  <title>Wiki</title>
+  <title>@TITLE@</title>
   <link rel="stylesheet" href="@CSS@style.css">
   <script async src="https://www.googletagmanager.com/gtag/js?id=G-XCMVL5K44X"></script>
   <script>