]> git.plutz.net Git - shellwiki/commitdiff
Support for %meta page pragma, adding meta-description to rendered html page master
authorPaul Hänsch <paul@plutz.net>
Tue, 11 Nov 2025 06:10:46 +0000 (07:10 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 11 Nov 2025 06:10:46 +0000 (07:10 +0100)
handlers/20_meta_description.sh [new file with mode: 0755]
pages/#page.md
pages/:de/#page.md
themes/default.sh

diff --git a/handlers/20_meta_description.sh b/handlers/20_meta_description.sh
new file mode 100755 (executable)
index 0000000..cec125d
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# Copyright 2025 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
+# copyright notice and this permission notice appear in all copies.
+# 
+# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+case $PATH_INFO in
+  *"/["*"]")
+    return 1;
+    ;;
+esac
+
+if acl_read ${PATH_INFO}; then
+  mdfile="$(mdfile "${PATH_INFO%/*}")"
+else
+  return 1
+fi
+
+if [ "$mdfile" ]; then
+  META_DESCRIPTION="$(sed -En '
+    s;\r$;;;
+    /^%meta([\t ]+.*)?$/bMETA;
+    20q;
+    b;
+
+    :META
+    s;(%(meta)?)?[\t ]*;;
+    p; n; s;\r$;;;
+    /^(%[ \t]+|%meta[ \t]+|[ \t]+)[^ \t\r].*$/bMETA;
+    /^(%[ \t]*|%meta[ \t]*)$/bMETA;
+  ' <"$mdfile")"
+
+  debug "$META_DESCRIPTION"
+else
+  return 1
+fi
+
+return 1
index ce03c129a231f5705906fb54fc4cfce275942835..7201468579cd3574a19336499cc52da57888989e 100644 (file)
@@ -3,6 +3,9 @@
 
 %title Home
 
 
 %title Home
 
+%meta Default start page of a fresh ShellWiki installation.
+      No user content has been added.
+
 It Works!
 =========
 <<search>>
 It Works!
 =========
 <<search>>
index 6c1e1ef5a675fe4bee176cd147f4e50e236b56d3..84ce51720bc202814dbbbf3daa9f5562947a944c 100644 (file)
@@ -3,6 +3,9 @@
 
 %title Start
 
 
 %title Start
 
+%meta Unveränderte Startseite einer frischen ShellWiki-Installation.
+      Vom Benutzer wurden keine Inhalte hinzugefügt.
+
 Es Funktioniert!
 ================
 <<search>>
 Es Funktioniert!
 ================
 <<search>>
index 8324bb2db1b157c26a2c068634612eddbd1d36f7..58f45a43ccb43559e1fa385f2942e120f055a8fc 100755 (executable)
@@ -30,6 +30,9 @@ theme_head(){
     printf  '<link rel="stylesheet" type="text/css" href="%s">' \
             "$(HTML "${css##*//}")"
   done
     printf  '<link rel="stylesheet" type="text/css" href="%s">' \
             "$(HTML "${css##*//}")"
   done
+  if [ "$META_DESCRIPTION" ]; then
+    printf '<meta name="description" content="%s">' "$(HTML "$META_DESCRIPTION")"
+  fi
 }
 
 theme_header(){
 }
 
 theme_header(){
@@ -209,6 +212,7 @@ theme_attachments(){
 theme_error(){
   local errno="$1"
 
 theme_error(){
   local errno="$1"
 
+  unset META_DESCRIPTION
   case $errno in
     400) printf "%s\r\n" "Status: 400 Bad Request";;
     403) printf "%s\r\n" "Status: 403 Forbidden";;
   case $errno in
     400) printf "%s\r\n" "Status: 400 Bad Request";;
     403) printf "%s\r\n" "Status: 403 Forbidden";;