]> git.plutz.net Git - shellwiki/blob - macros/changes
styling for <<changes>> macro
[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         $(git -C "$_DATA" log --pretty="format:%at %ai" -- "pages${page_abs}#page.md")
27         EOF
28   row="<td><a href=\"$(HTML "$page")\">$(HTML "$page")</a><span class=\"date\">${odate%% +*}</span></td>"
29   rowstate=''
30  
31   for l in $LANGUAGES; do
32     if [ -f "${_DATA}/pages/${page}:${l}/#page.md" ]; then
33       read lstamp ldate <<-EOF
34         $(git -C "$_DATA" log --pretty="format:%at %ai" -- "pages$(page_abs "${page_abs}:${l}")/#page.md")
35         EOF
36       if [ $lstamp -lt $ostamp ] 2>&-; then
37         row="${row}<td class=\"outdated\"><a href=\"$(HTML "${page}:${l}")\">outdated</a><span class=\"date\">${ldate%% +*}</span></td>"
38         [ "$rowstate" = "${rowstate%*outdated*}" ] && rowstate="${rowstate}${rowstate:+ }outdated"
39       else
40         row="${row}<td class=\"current\" ><a href=\"$(HTML "${page}:${l}")\">current</a ><span class=\"date\">${ldate%% +*}</span></td>"
41         [ "$rowstate" = "${rowstate%*current*}" ] && rowstate="${rowstate}${rowstate:+ }current"
42       fi
43     else
44       row="${row}<td class=\"missing\"><a href=\"$(HTML "${page}:${l}")\">missing</a></td>"
45       [ "$rowstate" = "${rowstate%*missing*}" ] && rowstate="${rowstate}${rowstate:+ }missing"
46     fi
47   done
48
49   printf '<tr class="%s">%s</tr>\n' "$rowstate" "$row"
50 done
51
52 printf '</tbody></table>'