3 # Copyright 2022 - 2023 Paul Hänsch
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . "$_EXEC/cgilite/cgilite.sh"
21 tags='' dir='' depth='' glob_system_pages=false
22 label='' labeltype='' altlabel='' cnt=0
25 while [ $# -gt 0 ]; do case $1 in
26 --system) glob_system_pages=true; shift 1;;
27 --depth) depth="$2" shift 2;;
28 \#*) tags="${tags}${tags:+ }${1###}"; shift 1;;
29 --h1|--h2|--h3|--h4|--h5|--h6|--label)
30 labeltype="${1#--}" label="$2"; shift 2;;
32 altlabel="$2"; shift 2;;
34 *) if [ ! "$dir" ]; then
36 set -- "$@" "$1"; shift 1;
37 elif [ ! "$depth" ]; then
40 set -- "$@" "$1"; shift 1;
44 [ "$*" ] || set -- "*"
45 [ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&- || depth=0
48 page_glob "$dir" "$depth"
52 while read -r page; do
53 pagedir="$(page_abs "$page")"
54 if [ -f "$_DATA/pages/${pagedir}/#page.md" -o \
55 -f "$_EXEC/pages/${pagedir}/#page.md" ] \
56 && acl_read "$pagedir" \
57 && has_tags "$pagedir" $tags
59 [ "$cnt" -eq 0 -a "$label" ] \
60 && printf '<%s class="macro pagelist label">%s</%s>' \
61 "$labeltype" "$(HTML "$label")" "$labeltype"
62 [ "$cnt" -eq 0 ] && printf '<ul class="macro pagelist">\n'
64 printf '<li><a href="%s">%s</a></li>' "$(HTML "$page")" "$(HTML "$page")"
69 if [ "$cnt" -gt 0 ]; then
71 elif [ "$altlabel" ]; then
72 printf '<label class="macro pagelist altlabel">%s</label>' "$(HTML "$altlabel")"