From 9228c5d601c0ffe2b334dd13af02c7be7fa57f79 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 17 May 2022 13:09:45 +0200 Subject: [PATCH] macro for page listing --- macros/pagelist | 23 ++++++++++++++++++++ tools.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 macros/pagelist diff --git a/macros/pagelist b/macros/pagelist new file mode 100755 index 0000000..24252a9 --- /dev/null +++ b/macros/pagelist @@ -0,0 +1,23 @@ +#!/bin/sh + +. "$_EXEC/cgilite/cgilite.sh" +. "$_EXEC/acl.sh" +. "$_EXEC/tools.sh" + +dir="${1:-./}" +depth="${2:-1}" + +printf '\n' diff --git a/tools.sh b/tools.sh index 591e9bc..f0c1538 100644 --- a/tools.sh +++ b/tools.sh @@ -19,3 +19,61 @@ size_human(){ printf "%i B" "$size" fi } + +page_glob(){ + local pattern="$1" IFS='' + local glob page pagedir + + case $pattern in + /*) + for glob in "$_DATA/pages"$pattern; do printf '%s\n' "${glob#"$_DATA/pages"}"; done + for glob in "$_EXEC/pages"$pattern; do printf '%s\n' "${glob#"$_EXEC/pages"}"; done + ;; + *) + for glob in "$_DATA/pages/$PATH_INFO"/$pattern; do printf '%s\n' "${glob#"$_DATA/pages/$PATH_INFO/"}"; done + for glob in "$_EXEC/pages/$PATH_INFO"/$pattern; do printf '%s\n' "${glob#"$_EXEC/pages/$PATH_INFO/"}"; done + ;; + esac \ + | sort -u \ + | while read -r page; do + case $page in + \#*|*/\#*) continue;; + /*) pagedir="$(PATH "$page")";; + *) pagedir="$(PATH "$PATH_INFO/$page")";; + esac + [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ] \ + && printf '%s\n' "$page" + done +} + +page_children(){ + local page="${1%/}/" depth="${2:--1}" + local glob pagedir IFS='' + + debug "CHILDREN $page $depth" + + [ "$depth" -eq 0 ] && return 0 + printf %s\\n "$page" + + case $page in + /*) + for glob in "$_DATA/pages/${page}"*/; do printf '%s\n' "${glob#"$_DATA/pages"}"; done + for glob in "$_EXEC/pages/${page}"*/; do printf '%s\n' "${glob#"$_EXEC/pages"}"; done + ;; + *) + for glob in "$_DATA/pages/$PATH_INFO/${page}"*/; do printf '%s\n' "${glob#"$_DATA/pages/$PATH_INFO/"}"; done + for glob in "$_EXEC/pages/$PATH_INFO/${page}"*/; do printf '%s\n' "${glob#"$_EXEC/pages/$PATH_INFO/"}"; done + ;; + esac \ + | debug \ + | sort -u \ + | while read -r page; do + case $page in + \#*|*/\#*) continue;; + /*) pagedir="$(PATH "$page")";; + *) pagedir="$(PATH "$PATH_INFO/$page")";; + esac + [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ] \ + && page_children "$page" "$((depth - 1))" + done +} -- 2.39.2