]> git.plutz.net Git - shellwiki/commitdiff
css pragma
authorPaul Hänsch <paul@plutz.net>
Thu, 26 May 2022 09:40:56 +0000 (11:40 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 26 May 2022 09:40:56 +0000 (11:40 +0200)
css.sh [new file with mode: 0755]
handlers/10_page.sh
themes/default.sh

diff --git a/css.sh b/css.sh
new file mode 100755 (executable)
index 0000000..97c03ac
--- /dev/null
+++ b/css.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+[ "$include_css" ] && return 0
+include_css="$0"
+
+css(){
+  local path="${1:-${PATH_INFO}}"
+  local pagefile css=''
+  # Get directory part of PATH_INFO
+  path="${path%/*}/./"
+
+  while :; do
+    [ "$path" = / ] && break
+    path="${path%/*/}/"
+
+    if   [ -f "$_DATA/pages/$path/#page.md" ]; then
+      pagefile="$_DATA/pages/$path/#page.md"
+    elif [ -f "$_EXEC/pages/$path/#page.md" ]; then
+      pagefile="$_EXEC/pages/$path/#page.md"
+    else
+      continue
+    fi
+
+    css="$(sed -En '
+      s;\r$;;;
+      /^%css([\t ]+.*)?$/bCSS;
+      20q;
+      b;
+
+      :CSS
+      s;(%(css)?)?[\t ]*;;
+      p; n; s;\r$;;;
+      /^(%[ \t]+|%css[ \t]+|[ \t]+)[^ \t\r]+$/bCSS;
+      /^(%[ \t]*|%css[ \t]*)$/bCSS;
+    ' <"$pagefile")${css}"
+  done
+
+  printf %s\\n "${css}"
+}
index 87af6850279a517c957be9440221c8a0f4a4b8e2..f8cbbafaae166c9f141af7d548c18f3a5cba47b5 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 . "$_EXEC/cgilite/file.sh"
+. "$_EXEC/css.sh"
 
 CACHE_AGE=${CACHE_AGE:-300}
 export MD_MACROS="$_EXEC/macros"
@@ -61,6 +62,7 @@ case "${PATH_INFO}" in
     elif ! acl_read "$PATH_INFO"; then
       theme_error 403
     else
+      PAGE_CSS="$(css "${PATH_INFO}")"
       theme_page "${PATH_INFO}"
     fi
     return 0
index 0b850078a06c321a6892813b1d129b8b1fabd9af..f9dfe4189963c55bcb283c1d78ae74f1d4f7d12c 100755 (executable)
@@ -3,11 +3,14 @@
 . "$_EXEC/tools.sh"
 
 theme_head(){
+  local IFS="$BR"
   printf '
   <meta name="viewport" content="width=device-width"/>
-  <link rel="stylesheet" type="text/css" href="%s/[.]/cgilite/common.css">
-  <link rel="stylesheet" type="text/css" href="%s/[.]/themes/default.css">
-  ' "$_BASE"
+  '
+  for css in "$_BASE/[.]/cgilite/common.css" "$_BASE/[.]/themes/default.css" $PAGE_CSS; do
+    printf  '<link rel="stylesheet" type="text/css" href="%s">' \
+            "$(HTML "${css#/}")"
+  done
 }
 
 theme_header(){