From: Paul Hänsch Date: Thu, 18 May 2023 10:57:45 +0000 (+0200) Subject: introduce css pragma as separate handler X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=c049bdadd263ad010dd11f3f2a89374ace20b785;p=shellwiki introduce css pragma as separate handler --- diff --git a/handlers/10_css.sh b/handlers/10_css.sh new file mode 100755 index 0000000..2efc07b --- /dev/null +++ b/handlers/10_css.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +css(){ + local path="${1:-${PATH_INFO}}" + local pagefile css='' + # Get directory part of PATH_INFO + path="${path%/*}/./" + + while :; do + [ "$path" = / ] && break + path="${path%/*/}/" + + if ! acl_read "$path"; then + continue + elif [ -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")${BR}${css}" + done + + printf %s\\n "${css}" +} + +PAGE_CSS="$(css "${PATH_INFO}")" + +return 1 diff --git a/handlers/10_page.sh b/handlers/10_page.sh index f8cbbaf..87af685 100755 --- a/handlers/10_page.sh +++ b/handlers/10_page.sh @@ -1,7 +1,6 @@ #!/bin/sh . "$_EXEC/cgilite/file.sh" -. "$_EXEC/css.sh" CACHE_AGE=${CACHE_AGE:-300} export MD_MACROS="$_EXEC/macros" @@ -62,7 +61,6 @@ 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