]> git.plutz.net Git - shellwiki/commitdiff
basic revision listing
authorPaul Hänsch <paul@plutz.net>
Sun, 22 May 2022 11:12:52 +0000 (13:12 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 22 May 2022 11:12:52 +0000 (13:12 +0200)
handlers/20_revision.sh [new file with mode: 0644]
macros/revisions [new file with mode: 0755]

diff --git a/handlers/20_revision.sh b/handlers/20_revision.sh
new file mode 100644 (file)
index 0000000..a9c5d39
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+case "${PATH_INFO}" in
+  */\[revision\]|*/\[revision\]/)
+    if ! acl_read "${PATH_INFO%\[revision\]?}"; then
+      theme_error 403
+    else
+      theme_revisions "${PATH_INFO%\[revision\]?}"
+    fi
+    return 0
+    ;;
+  */[revision]/*):;;
+esac
+
+return 1
diff --git a/macros/revisions b/macros/revisions
new file mode 100755 (executable)
index 0000000..c6fb8fa
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+. "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/tools.sh"
+. "$_EXEC/acl.sh"
+
+page="$1"
+page_abs="$(page_abs "$page")"
+
+if ! acl_read "$page_abs"; then
+  return 0
+elif [ ! "$(which git)" ]; then
+  printf '<div class="macro revisions error">GIT is not available to handle revisioning.</div>'
+fi
+
+printf '<ul class="macro revisions">'
+  IFS="        "
+  git -C "$_DATA" log --date=format:"%a, %x %H:%M" \
+                      --pretty=format:"%h      %cd     %s%n" \
+                      -- "pages${page_abs}#page.md" \
+  | while read hash date message; do
+    user="${message% @*}"; user="${user##*@ }"
+    printf '<a href="%s"><span class="hash">%s</span><span="date">%s</span><span class="user">%s</span></a>' \
+      "$(HTML "${page%/}/[revisions]/$hash")" "$(HTML "$hash")" "$(HTML "$date")" "$(HTML "$user")"
+  done
+printf '</ul>'