]> git.plutz.net Git - shellwiki/blobdiff - handlers/20_title.sh
universal page_title function
[shellwiki] / handlers / 20_title.sh
index 3da07fffab3ed2df4ad141ae2a0c88993143945d..35b5d3c52d194336c2b81239b924a751c52051cf 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright 2023 Paul Hänsch
+# Copyright 2023, 2024 Paul Hänsch
 # 
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-if acl_read ${PATH_INFO}; then
-  mdfile="$(mdfile "${PATH_INFO%/*}")"
-else
-  PAGE_TITLE="${SITE_TITLE}"
-  return 1
+if acl_read "${PATH_INFO}"; then
+  PAGE_TITLE="$(page_title "${PATH_INFO%/*}")"
 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}"
+PAGE_TITLE="${PAGE_TITLE:-${SITE_TITLE:-${PATH_INFO}}}${PAGE_TITLE:+${SITE_TITLE:+ - ${SITE_TITLE}}}"
 
 return 1