3 # Copyright 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/datetime.sh"
22 tags='' ntags='' dir='' depth='' glob_system_pages=false
23 label='' labeltype='' altlabel='' cnt=0
26 while [ $# -gt 0 ]; do case $1 in
27 --system) glob_system_pages=true; shift 1;;
28 --depth) depth="$2" shift 2;;
29 \#*) tags="${tags}${tags:+ }${1###}"; shift 1;;
30 \!*) ntags="${ntags}${ntags:+ }${1##!}"; shift 1;;
31 --h1|--h2|--h3|--h4|--h5|--h6|--label)
32 labeltype="${1#--}" label="$2"; shift 2;;
34 altlabel="$2"; shift 2;;
36 *) if [ ! "$dir" ]; then
38 set -- "$@" "$1"; shift 1;
39 elif [ ! "$depth" ]; then
42 set -- "$@" "$1"; shift 1;
46 [ "$*" ] || set -- "*"
47 [ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&- || depth=0
53 dstart="$(date -d "${DY}-${DM}-01" +%s)"
55 && dend="$(date -d "${DY}-$(( ${DM#0} + 1))-01" +%s)" \
56 || dend="$(date -d "$(( ${DY#0} + 1))-01-01" +%s)"
59 local start="$1" end="$2" rrfreq="$3" rrint="$4" rrend="$5" evtitle="$6" evlink="$7"
63 [ "$rrend" -eq -1 ] && rrend=9999999999
67 nend=$(( rrfreq * 86400 - (dstart - end) % (rrfreq * 86400) + dstart ))
68 nstart=$(( start - end + nend))
69 debug "[ $nend -lt $dend -a $nstart -lt $rrend ]"
70 while [ "$nend" -lt "$dend" -a "$nstart" -lt "$rrend" ]; do
71 printf '%i %i %s %s\n' "$nstart" "$nend" "$evtitle" "$evlink"
72 # printf '%i %i %s\n' "$nstart" "$nend" "$evlink"
73 nstart="$((nstart + rrfreq * 86400))"
74 nend="$((nstart - start + end))"
78 nend=$(( rrfreq * 604800 - (dstart - end) % (rrfreq * 604800) + dstart ))
79 nstart=$(( start - end + nend))
80 while [ "$nend" -lt "$dend" -a "$nstart" -lt "$rrend" ]; do
81 printf '%i %i %s %s\n' "$nstart" "$nend" "$evtitle" "$evlink"
82 nstart="$((nstart + rrfreq * 7 * 86400))"
83 nend="$((nstart - start + end))"
87 { read _y _m _d; read y m d; } <<-EOF
88 $(date -d @$dstart +"%Y %_m %_d"
89 date -d @$start +"%Y %_m %_d"
92 _m=$((_y * 12 + _m)) m=$((y * 12 + m))
94 m=$(( rrfreq - ((_m - m - 1) % rrfreq + 1) + _m ))
95 nstart="$(printf '%04i-%02i-%02i' "$(( (m - 1) / 12 ))" "$(( (m - 1) % 12 + 1 ))" "$d")"
96 if isdate "$nstart" && [ "$(date -d "$nstart" +%s)" -ge "$dstart" ]; then
101 nstart="$(date -d "$nstart $start_time" +%s)"
102 nend="$((end - start + nstart))"
103 while [ "$nend" -lt "$dend" -a "$nstart" -lt "$rrend" ]; do
104 printf '%i %i %s %s\n' "$nstart" "$nend" "$evtitle" "$evlink"
106 nstart="$(printf '%04i-%02i-%02i' "$(( (m - 1) / 12 ))" "$(( (m - 1) % 12 + 1 ))" "$d")"
107 nstart="$(date -d "$nstart $start_time" +%s)"
108 nend="$((nstart - start + end))"
112 { read _y _m _d; read y m d; } <<-EOF
113 $(date -d @$dstart +"%Y %_m %_d"
114 date -d @$start +"%Y %_m %_d"
118 y=$(( rrfreq - ((_y - y - 1) % rrfreq + 1) + _y ))
119 nstart="$(printf '%04i-%02i-%02i' "$y" "$m" "$d")"
120 if isdate "$nstart" && [ "$(date -d "$nstart" +%s)" -ge "$dstart" ]; then
123 _y="$((_y + rrfreq))"
125 nstart="$(date -d "$nstart $start_time" +%s)"
126 nend="$((end - start + nstart))"
127 while [ "$nend" -lt "$dend" -a "$nstart" -lt "$rrend" ]; do
128 printf '%i %i %s %s\n' "$nstart" "$nend" "$evtitle" "$evlink"
130 nstart="$(printf '%04i-%02i-%02i' "$y" "$m" "$d")"
131 nstart="$(date -d "$nstart $start_time" +%s)"
132 nend="$((nstart - start + end))"
136 printf '%i %i %s %s\n' "$start" "$end" "$evtitle" "$evlink"
143 page_glob "$dir" "$depth"
146 | while read -r page; do
147 pagedir="$(page_abs "$page")"
148 if [ -f "$_DATA/pages/${pagedir}/#events" ] \
149 && acl_read "$pagedir" \
150 && has_tags "$pagedir" $tags \
151 && ! has_tag "$pagedir" $ntags
153 cat "$_DATA/pages/${pagedir}/#events"
156 | while read -r junk1 tstart tend rrfreq rrint rrend evtitle evlink junk2; do
157 if [ "$tend" -gt "$dstart" -a "$tstart" -lt "$dend" ] \
158 || [ "$rrend" -gt "$dstart" -o "$rrend" -eq -1 ]; then
159 expand "$tstart" "$tend" "$rrfreq" "$rrint" "$rrend" "$evtitle" "$evlink"
168 printf '<ul class="macro calendar">\n'
169 printf '%s\n' "${events}" \
170 | while read start end name link; do
171 day="$((start / 86400))"
172 if [ "$day" != "$lday" ]; then
173 [ "$lday" ] && printf '</ul></li>'
174 date -d "@$start" +'<li><label>%A, %F</label><ul class="day">'
177 printf '<li>%s: <a href="%s">%s</a></li>' \
178 "$(date -d "@$start" +"%T")" "$(URL "${link%%#*}")#$(URL "${link#*#}")" "$(HTML "${name}")"
180 printf '</ul></li></ul>'