From 4eb1ee6d2d6889d5c8160590c1ce59f4c78cdf68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 26 May 2022 11:40:56 +0200 Subject: [PATCH] css pragma --- css.sh | 39 +++++++++++++++++++++++++++++++++++++++ handlers/10_page.sh | 2 ++ themes/default.sh | 9 ++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100755 css.sh diff --git a/css.sh b/css.sh new file mode 100755 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}" +} diff --git a/handlers/10_page.sh b/handlers/10_page.sh index 87af685..f8cbbaf 100755 --- a/handlers/10_page.sh +++ b/handlers/10_page.sh @@ -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 diff --git a/themes/default.sh b/themes/default.sh index 0b85007..f9dfe41 100755 --- a/themes/default.sh +++ b/themes/default.sh @@ -3,11 +3,14 @@ . "$_EXEC/tools.sh" theme_head(){ + local IFS="$BR" printf ' - - - ' "$_BASE" + ' + for css in "$_BASE/[.]/cgilite/common.css" "$_BASE/[.]/themes/default.css" $PAGE_CSS; do + printf '' \ + "$(HTML "${css#/}")" + done } theme_header(){ -- 2.39.2