3 # Copyright 2022 - 2024 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"
20 . "$_EXEC/cgilite/db23.sh"
22 tags='' ntags='' dir='' depth='' glob_system_pages=false
23 label='' labeltype='' altlabel='' titles='' db3_data=''
24 DB3 new # Use DB3 for in-memory cache
27 while [ $# -gt 0 ]; do case $1 in
28 --system) glob_system_pages=true; shift 1;;
29 --depth) depth="$2"; shift 2;;
30 --title|--titles) titles=true; shift 1;;
31 \#*) tags="${tags}${tags:+ }${1###}"; shift 1;;
32 \!*) ntags="${ntags}${ntags:+ }${1##!}"; shift 1;;
33 --h1|--h2|--h3|--h4|--h5|--h6|--label)
34 labeltype="${1#--}" label="$2"; shift 2;;
35 --alt-label|--altlabel)
36 altlabel="$2"; shift 2;;
38 *) if [ ! "$dir" ]; then
40 set -- "$@" "$1"; shift 1;
41 elif [ ! "$depth" ]; then
44 set -- "$@" "$1"; shift 1;
48 [ "$*" ] || set -- "*"
49 [ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&- || depth=0
52 # print page URL and resolve page title (for use with --title flag)
53 # avoid calling this function via a subshell (i.e. $(print_page *))
54 # because it should be able to write its cache variable
55 local page="${1%/}/" title='' pfrag=''
58 # resolve name of each path element
59 while [ "${pfrag%/*}" -a "${pfrag%/*}" != "${pfrag}" ]; do
61 title="$(DB3 get "${pfrag}" || ! page_title "$(page_abs "${pfrag}")")/${title}" && break
63 # keep resolved names in cache
64 DB3 set "${page%/*}" "${title%/}"
66 [ "${page#/}" != "${page}" ] && title="/$title"
67 printf '%s %s\n' "$(URL "$page")" "$(HTML "${title}")"
72 page_glob "$dir" "$depth"
75 | while read -r page; do
76 pagedir="$(page_abs "$page")"
77 if [ -f "$_DATA/pages/${pagedir}/#page.md" -o \
78 -f "$_EXEC/pages/${pagedir}/#page.md" ] \
79 && acl_read "$pagedir" \
80 && has_tags "$pagedir" $tags \
81 && ! has_tag "$pagedir" $ntags
83 # Be careful, not to fork the print_page function into a subshell
84 # as it must be able to write its cache to the current context
86 && print_page "$page" \
87 || printf '%s %s\n' "$(URL "$page")" "$(HTML "$page")"
92 if [ "$pagelist" ]; then
94 && printf '<%s class="macro pagelist label">%s</%s>' "$labeltype" "$(HTML "$label")" "$labeltype"
96 printf '<ul class="macro pagelist">\n'
97 printf %s\\n "$pagelist" \
99 | while read -r url title; do
100 printf '<li><a href="%s">%s</a></li>\n' "${url}" "${title}"
104 elif [ "$altlabel" ]; then
105 printf '<label class="macro pagelist altlabel">%s</label>' "$(HTML "$altlabel")"