]> git.plutz.net Git - shellwiki/commitdiff
default behaviour of page_children function
authorPaul Hänsch <paul@plutz.net>
Tue, 17 May 2022 16:29:12 +0000 (18:29 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 17 May 2022 16:29:12 +0000 (18:29 +0200)
macros/pagelist
tools.sh

index e8e9b04ad486aac46e829a3c7597e31b664af61a..e9f5a33e191be7ba9796e2aa8911cdccd6d1b5db 100755 (executable)
@@ -10,7 +10,8 @@ depth="${2:-1}"
 printf '<ul class="pagelist">\n'
   page_glob "$dir" \
   | while read -r glob; do
-    page_children "$glob" "$depth"
+    printf %s\\n "$glob"
+    page_children "$glob" "$((depth - 1))"
   done \
   | while read -r page; do
     case $page in
index 926c7e4e3bdf51ed763aa55b862dd25d53bdabfb..e40e25f4be075bb97589fc6415e09c3c2dc5b025 100644 (file)
--- a/tools.sh
+++ b/tools.sh
@@ -47,11 +47,11 @@ page_glob(){
 }
 
 page_children(){
-  local page="${1%/}/" depth="${2:--1}"
+  local page="${1:-${PATH_INFO}}" depth="${2:-1}"
   local glob pagedir IFS=''
+  page="${page%/}/"
 
   [ "$depth" -eq 0 ] && return 0
-  printf %s\\n "$page"
 
   case $page in
   /*)
@@ -70,7 +70,9 @@ page_children(){
       /*) pagedir="$(PATH "$page")";;
       *)  pagedir="$(PATH "$PATH_INFO/$page")";;
     esac
-    [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ] \
-    && page_children "$page" "$((depth - 1))"
+    if [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ]; then
+      printf %s\\n "$page"
+      page_children "$page" "$((depth - 1))"
+    fi
   done
 }