X-Git-Url: https://git.plutz.net/?a=blobdiff_plain;f=macros%2Finclude;h=5254a2609c91623d2edae92bc14361fc71219407;hb=116a9fbba5874eec7efb4f2253844e8158fffde9;hp=b1d1e776765263d0da4086cfed16d2e801520e1b;hpb=9422fa86d51fdaba072d04f6b0ae5d7e589a4439;p=shellwiki diff --git a/macros/include b/macros/include index b1d1e77..5254a26 100755 --- a/macros/include +++ b/macros/include @@ -1,15 +1,10 @@ #!/bin/sh . "$_EXEC/cgilite/cgilite.sh" -. "$_EXEC/cgilite/users.sh" . "$_EXEC/acl.sh" . "$_EXEC/tools.sh" -from=1 -to=\$ -rev='' -items=\$ -path_info="$PATH_INFO" +from='1'; to='$'; rev=''; items='$'; link='true' while [ $# -gt 0 ]; do case $1 in --from) from="$2"; shift 2;; @@ -19,6 +14,7 @@ while [ $# -gt 0 ]; do case $1 in --items) items="$2"; shift 2;; items=*) items="${1#*=}"; shift 1;; --rev|--reverse) rev="-r"; shift 1;; + --nolink) link=""; shift 1;; *) page="$1"; shift 1;; esac; done @@ -26,7 +22,7 @@ if ! printf %s\\n "$from" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then debug 'Include macro invalid argument: "from"' exit 1 fi -if ! printf %s\\n "$to" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then +if ! printf %s\\n "$to" |grep -qEx '\$|[0-9]+|/([^/\\]|\\/|\\.)*/'; then debug 'Include macro Invalid argument: "to"' exit 1 fi @@ -39,25 +35,29 @@ page_glob "$page" \ | sort $rev \ | sed "${items}q" \ | while read glob; do - case $glob in - /*) export PATH_INFO="$(PATH "$glob")";; - *) export PATH_INFO="$(PATH "$path_info/$glob")";; - esac - acl_read || continue - if [ -f "$_DATA/pages/$PATH_INFO/#page.md" ]; then - mdfile="$_DATA/pages/$PATH_INFO/#page.md" - elif [ -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then - mdfile="$_EXEC/pages/$PATH_INFO/#page.md" - else - continue - fi - printf '
' "$(HTML "$glob")" - ( cd -- "${mdfile%/*}" + page="$(page_abs "$glob")" + acl_read "$page" || continue + mdfile="$(mdfile "$page")" || continue + hglob="$(HTML "$glob")" + refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')" + [ "$link" ] \ + && printf '
+ %s +
' \ + "${hglob}" "${hglob}" "${hglob}" \ + || printf '
+
' \ + "${hglob}" + ( # PATH_INFO may be used by macros in the included page + export PATH_INFO="$page" + cd -- "${mdfile%/*}/" sed -n "${from},${to}p" <"$mdfile" \ | md \ | grep -vx '' ) | sed -E ' - s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"$(HTML "$glob")"'\3"\4;g + s;(<[^>]+ )(href|src)="([^"]+://[^"]*|[mM][aA][iI][lL][tT][oO]:[^"]*)"([^>]*>);\1\2="/#safe/\3"\4;g + s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"${refpfx}"'\3"\4;g + s;(<[^>]+ )(href|src)="/#safe/([^"]*)"([^>]*>);\1\2="\3"\4;g ' - printf '
' + printf '
' done