. "$_EXEC/acl.sh"
. "$_EXEC/tools.sh"
-dir="${1:-./}"
-depth="${2:-1}"
+while [ $# -gt 0 ]; do case $1 in
+ --system) glob_system_pages=true; shift 1;;
+ --depth) depth="$2" shift 2;;
+ *) if [ ! "$dir" ]; then
+ dir="$1"
+ elif [ ! "$depth" ]; then
+ depth="$1"
+ fi
+ shift 1;;
+esac; done
+
+[ "$dir" ] || dir=./
+[ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&0 || depth=0
+
printf '<ul class="pagelist">\n'
- page_glob "$dir" \
+ page_glob "$dir" "$depth" \
| while read -r glob; do
printf %s\\n "$glob"
- page_children "$glob" "$((depth - 1))"
done \
| while read -r page; do
pagedir="$(page_abs "$page")"
}
page_glob(){
- local pattern="${1%/}/" IFS=''
+ local pattern="${1%/}/" depth="${2:-0}" IFS=''
local glob page pagedir
case $pattern in
| sort -u \
| while read -r page; do
case $page in
- \#*|*/\#*) continue;;
- *) pagedir="$(page_abs "$page")";;
- esac
- [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ] \
- && printf '%s\n' "$page"
- done
-}
-
-page_children(){
- local page="${1:-${PATH_INFO}}" depth="${2:-1}"
- local glob pagedir IFS=''
- page="${page%/}/"
-
- [ "$depth" -eq 0 ] && return 0
-
- 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 \
- | sort -u \
- | while read -r page; do
- case $page in
- \#*|*/\#*) continue;;
+ \#*|*/\#*) # Not a page directory (just a metadata dir)
+ continue
+ ;;
+ \[*\]/*|*/\[*\]/*) # Omit "system" pages unless explicitly wanted
+ [ "$glob_system_pages" != true ] \
+ && continue \
+ || pagedir="$(page_abs "$page")"
+ ;;
+ \:*|*/\:*) # Omit translation pages if translations are enabled
+ [ "$LANGUAGE_DEFAULT" ] \
+ && continue \
+ || pagedir="$(page_abs "$page")"
+ ;;
*) pagedir="$(page_abs "$page")";;
esac
if [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ]; then
- printf %s\\n "$page"
- page_children "$page" "$((depth - 1))"
+ printf '%s\n' "$page"
+ if ! [ "$depth" -eq 0 ]; then
+ PATH_INFO="$pagedir" page_glob "*" "$((depth - 1))" \
+ | while read -r glob; do printf %s%s\\n "$page" "$glob"; done
+ fi
fi
done
}