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