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
26 [ "$LANGUAGE_DEFAULT" ] && titles=true
29 while [ $# -gt 0 ]; do case $1 in
31 glob_system_pages=true; shift 1;;
34 --title|--titles|-titles|-title)
35 titles=true; shift 1;;
36 --no-title|--no-titles|--notitle|--notitles|-no-title|-no-titles|-notitle|-notitles)
37 titles=false; shift 1;;
38 \#*) tags="${tags}${tags:+ }${1###}"; shift 1;;
39 \!*) ntags="${ntags}${ntags:+ }${1##!}"; shift 1;;
40 --h1|--h2|--h3|--h4|--h5|--h6|--label)
41 labeltype="${1#--}" label="$2"; shift 2;;
42 --alt-label|--altlabel)
43 altlabel="$2"; shift 2;;
45 *) if [ ! "$dir" ]; then
47 set -- "$@" "$1"; shift 1;
48 elif [ ! "$depth" ]; then
51 set -- "$@" "$1"; shift 1;
55 [ "$*" ] || set -- "*"
56 [ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&- || depth=0
59 # print page URL and resolve page title (for use with --title flag)
60 # avoid calling this function via a subshell (i.e. $(print_page *))
61 # because it should be able to write its cache variable
62 local page="${1%/}/" title='' pfrag=''
65 # resolve name of each path element
66 while [ "${pfrag%/*}" -a "${pfrag%/*}" != "${pfrag}" ]; do
68 title="$(DB3 get "${pfrag}" || ! page_title "$(page_abs "${pfrag}")")/${title}" && break
70 # keep resolved names in cache
71 DB3 set "${page%/*}" "${title%/}"
73 [ "${page#/}" != "${page}" ] && title="/$title"
74 printf '%s %s\n' "$(URL "$page")" "$(HTML "${title}")"
79 page_glob "$dir" "$depth"
82 | while read -r page; do
83 pagedir="$(page_abs "$page")"
84 if [ -f "$_DATA/pages/${pagedir}/#page.md" -o \
85 -f "$_EXEC/pages/${pagedir}/#page.md" ] \
86 && acl_read "$pagedir" \
87 && has_tags "$pagedir" $tags \
88 && ! has_tag "$pagedir" $ntags
90 # Be careful, not to fork the print_page function into a subshell
91 # as it must be able to write its cache to the current context
93 && print_page "$page" \
94 || printf '%s %s\n' "$(URL "$page")" "$(HTML "$page")"
99 if [ "$pagelist" ]; then
101 && printf '<%s class="macro pagelist label">%s</%s>' "$labeltype" "$(HTML "$label")" "$labeltype"
103 printf '<ul class="macro pagelist">\n'
104 printf %s\\n "$pagelist" \
106 | while read -r url title; do
107 printf '<li><a href="%s">%s</a></li>\n' "${url}" "${title}"
111 elif [ "$altlabel" ]; then
112 printf '<label class="macro pagelist altlabel">%s</label>' "$(HTML "$altlabel")"