]> git.plutz.net Git - shellwiki/blob - handlers/10_css.sh
Merge commit '6bc502434737d7f08379e79b94fc6fda424ef779'
[shellwiki] / handlers / 10_css.sh
1 #!/bin/sh
2
3 # Copyright 2023 Paul Hänsch
4
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17 css(){
18   local path="${1:-${PATH_INFO}}"
19   local pagefile css=''
20   # Get directory part of PATH_INFO
21   path="${path%/*}/./"
22
23   while :; do
24     [ "$path" = / ] && break
25     path="${path%/*/}/"
26
27     if ! acl_read "$path"; then
28       continue
29     elif [ -f "$_DATA/pages/$path/#page.md" ]; then
30       pagefile="$_DATA/pages/$path/#page.md"
31     elif [ -f "$_EXEC/pages/$path/#page.md" ]; then
32       pagefile="$_EXEC/pages/$path/#page.md"
33     else
34       continue
35     fi
36
37     css="$(sed -En '
38       s;\r$;;;
39       /^%css([\t ]+.*)?$/bCSS;
40       20q;
41       b;
42
43       :CSS
44       s;(%(css)?)?[\t ]*;;
45       p; n; s;\r$;;;
46       /^(%[ \t]+|%css[ \t]+|[ \t]+)[^ \t\r]+$/bCSS;
47       /^(%[ \t]*|%css[ \t]*)$/bCSS;
48     ' <"$pagefile")${BR}${css}"
49   done
50
51   printf %s\\n "${css}"
52 }
53
54 PAGE_CSS="$(css "${PATH_INFO}")"
55
56 return 1