]> git.plutz.net Git - shellwiki/blob - macros/changes
<<changes>> macro: fallback to filesystem timestamps if revisioning is disabled
[shellwiki] / macros / changes
1 #!/bin/sh
2
3 . "$_EXEC/cgilite/cgilite.sh"
4 . "$_EXEC/tools.sh"
5 . "$_EXEC/acl.sh"
6
7 LANGUAGES='' glob="/" depth=-1
8 while [ $# -gt 0 ]; do case $1 in
9   --system) glob_system_pages=true; shift 1;;
10   :*) LANGUAGES="${LANGUAGES}${LANGUAGES:+ }${1#:}"; shift 1;;
11   --depth) depth="$2"; shift 2;;
12   *) glob="$1"; shift 1;;
13 esac; done
14
15 page='' page_abs='' ostamp='' odate='' lstamp='' ldate='' row='' rowstate=''
16
17 printf '<table class="macro changes"><thead>\n<th>Page</th>'
18 for l in $LANGUAGES; do printf '<th>%s</th>' "$l"; done
19 printf '\n</thead><tbody>\n'
20
21 page_glob "$glob" "$depth" |while read page; do
22   page_abs="$(page_abs "$page")"
23   acl_read "${page_abs}" || continue
24
25   read ostamp odate <<-EOF
26         $([ "$REV_PAGES" = true ] \
27           && git -C "$_DATA" log --pretty="format:%at %ai" -- "pages${page_abs}#page.md" \
28           || stat -c "%Y %y" -- "$_DATA/pages${page_abs}#page.md"
29         )
30         EOF
31   row="<td><a href=\"$(HTML "$page")\">$(HTML "$page")</a><span class=\"date\">${odate%%[+.]*}</span></td>"
32   rowstate=''
33  
34   for l in $LANGUAGES; do
35     if [ -f "${_DATA}/pages/${page}:${l}/#page.md" ]; then
36       read lstamp ldate <<-EOF
37         $([ "$REV_PAGES" = true ] \
38           && git -C "$_DATA" log --pretty="format:%at %ai" -- "pages$(page_abs "${page_abs}:${l}")/#page.md" \
39           || stat -c "%Y %y" -- "$_DATA/pages$(page_abs "${page_abs}:${l}")/#page.md"
40         )
41         EOF
42       if [ $lstamp -lt $ostamp ] 2>&-; then
43         row="${row}<td class=\"outdated\"><a href=\"$(HTML "${page}:${l}")\">outdated</a><span class=\"date\">${ldate%%[+.]*}</span></td>"
44         [ "$rowstate" = "${rowstate%*outdated*}" ] && rowstate="${rowstate}${rowstate:+ }outdated"
45       else
46         row="${row}<td class=\"current\" ><a href=\"$(HTML "${page}:${l}")\">current</a ><span class=\"date\">${ldate%%[+.]*}</span></td>"
47         [ "$rowstate" = "${rowstate%*current*}" ] && rowstate="${rowstate}${rowstate:+ }current"
48       fi
49     else
50       row="${row}<td class=\"missing\"><a href=\"$(HTML "${page}:${l}")\">missing</a></td>"
51       [ "$rowstate" = "${rowstate%*missing*}" ] && rowstate="${rowstate}${rowstate:+ }missing"
52     fi
53   done
54
55   printf '<tr class="%s">%s</tr>\n' "$rowstate" "$row"
56 done
57
58 printf '</tbody></table>'