]> git.plutz.net Git - shellwiki/commitdiff
code cleanup (limit overriding PATH_INFO), remove outside div wrapper for include
authorPaul Hänsch <paul@plutz.net>
Fri, 3 Jun 2022 11:22:05 +0000 (13:22 +0200)
committerPaul Hänsch <paul@plutz.net>
Fri, 3 Jun 2022 11:22:05 +0000 (13:22 +0200)
macros/include

index 9f3339df5201e617ebfb443d7dc9f3575771eead..5eb613aa4659ec96128a0a6da670fc71a17719ac 100755 (executable)
@@ -4,11 +4,7 @@
 . "$_EXEC/acl.sh"
 . "$_EXEC/tools.sh"
 
-from=1
-to=\$
-rev=''
-items=\$
-path_info="$PATH_INFO"
+from='1'; to='$'; rev=''; items='$'
 
 while [ $# -gt 0 ]; do case $1 in
   --from) from="$2"; shift 2;;
@@ -34,27 +30,22 @@ if ! printf %s\\n "$items" |grep -qEx '\$|[0-9]+'; then
   exit 1
 fi
 
-printf '<div class="macro include wrapper">'
 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
+  page="$(page_abs "$glob")"
+  acl_read "$page" || continue
+  mdfile="$(mdfile "$page")" || continue
   hglob="$(HTML "$glob")"
   refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')"
-  printf '<div class="macro include page"><article class="include" id="include_%s">' "${hglob}"
-  ( cd -- "${mdfile%/*}"
+  printf '<div class="macro include">
+            <a class="include link" href="%s">%s</a>
+            <article class="include" id="include_%s">' \
+         "${hglob}" "${hglob}" "${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 ''
@@ -63,8 +54,5 @@ page_glob "$page" \
     s;(<[^>]+ )(href|src)="([^#/"][^"]*)"([^>]*>);\1\2="'"${refpfx}"'\3"\4;g
     s;(<[^>]+ )(href|src)="/#safe/([^"]*)"([^>]*>);\1\2="\3"\4;g
   '
-  printf '</article>'
-  printf '<a class="include link" href="%s">%s</a>' "${hglob}" "${hglob}"
-  printf '</div>'
+  printf '</article></div>'
 done
-printf '</div>'