]> git.plutz.net Git - shellwiki/commitdiff
Set page title in HTML Header
authorPaul Hänsch <paul@plutz.net>
Thu, 25 May 2023 10:12:33 +0000 (12:12 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 25 May 2023 10:12:33 +0000 (12:12 +0200)
handlers/20_title.sh [new file with mode: 0755]
handlers/30_page.sh [moved from handlers/20_page.sh with 100% similarity]
themes/default.sh

diff --git a/handlers/20_title.sh b/handlers/20_title.sh
new file mode 100755 (executable)
index 0000000..4288b31
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+if acl_read ${PATH_INFO%/*}; then
+  mdfile="$(mdfile "${PATH_INFO%/*}")"
+else
+  PAGE_TITLE="${SITE_TITLE}"
+  return 1
+fi
+
+if [ "$mdfile" ]; then
+  PAGE_TITLE="$(
+    sed -nE '
+      s;^%title[ \t]+([[:graph:]][[:print:]]+)\r?$;\1;p; tQ;
+      b; :Q q;
+    ' "$mdfile"
+  )"
+  [ ! "${PAGE_TITLE}" ] && PAGE_TITLE="$(
+    MD_MACROS="" md <"$mdfile" \
+    | sed -nE '
+      s;^.*<h1[^>]*>(.*>)?([^<]+)(<.*)?</h1>.*$;\2;p; tQ;
+      s;^.*<h2[^>]*>(.*>)?([^<]+)(<.*)?</h2>.*$;\2;p; tQ;
+      b; :Q q;
+    '
+  )"
+else
+  PAGE_TITLE="${SITE_TITLE}"
+  return 1
+fi
+
+case $PATH_INFO in
+  *"/[attachment]")
+    PAGE_TITLE="${PAGE_TITLE} (Attachments)"
+    ;;
+  *"/[revision]")
+    PAGE_TITLE="${PAGE_TITLE} (Revisions)"
+    ;;
+esac
+
+[ "$PAGE_TITLE" ] \
+&& PAGE_TITLE="${PAGE_TITLE}${SITE_TITLE:+ - ${SITE_TITLE}}" \
+|| PAGE_TITLE="${SITE_TITLE}"
+
+return 1
similarity index 100%
rename from handlers/20_page.sh
rename to handlers/30_page.sh
index 0439f0d642421244c6049fa2ef9896389a5e21a5..541f71361ae5e24a1f4b09f61d91172c4dff5b35 100755 (executable)
@@ -40,7 +40,7 @@ theme_pagemenu(){
 
 theme_page(){
   local page="$1" title="$2"
-  title="$(HTML "${title:-"${page}"}")"
+  title="$(HTML "${title:-"${PAGE_TITLE:-"${page}"}"}")"
 
   # Important! Web Server response including newline
   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""