]> git.plutz.net Git - shellwiki/blob - handlers/10_css.sh
rewrite links to carry language tag, needs improvement
[shellwiki] / handlers / 10_css.sh
1 #!/bin/sh
2
3 css(){
4   local path="${1:-${PATH_INFO}}"
5   local pagefile css=''
6   # Get directory part of PATH_INFO
7   path="${path%/*}/./"
8
9   while :; do
10     [ "$path" = / ] && break
11     path="${path%/*/}/"
12
13     if ! acl_read "$path"; then
14       continue
15     elif [ -f "$_DATA/pages/$path/#page.md" ]; then
16       pagefile="$_DATA/pages/$path/#page.md"
17     elif [ -f "$_EXEC/pages/$path/#page.md" ]; then
18       pagefile="$_EXEC/pages/$path/#page.md"
19     else
20       continue
21     fi
22
23     css="$(sed -En '
24       s;\r$;;;
25       /^%css([\t ]+.*)?$/bCSS;
26       20q;
27       b;
28
29       :CSS
30       s;(%(css)?)?[\t ]*;;
31       p; n; s;\r$;;;
32       /^(%[ \t]+|%css[ \t]+|[ \t]+)[^ \t\r]+$/bCSS;
33       /^(%[ \t]*|%css[ \t]*)$/bCSS;
34     ' <"$pagefile")${BR}${css}"
35   done
36
37   printf %s\\n "${css}"
38 }
39
40 PAGE_CSS="$(css "${PATH_INFO}")"
41
42 return 1