]> git.plutz.net Git - shellwiki/commitdiff
show diff of original language version on revisions page
authorPaul Hänsch <paul@plutz.net>
Thu, 27 Jul 2023 07:33:35 +0000 (09:33 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 27 Jul 2023 07:33:35 +0000 (09:33 +0200)
macros/revisions
themes/default.css

index 4271149cffbd8074d89f16d88418b26f5f842441..75440d60609fcb070d79dd2a23aaa3278eaf5925 100755 (executable)
@@ -4,16 +4,44 @@
 . "$_EXEC/tools.sh"
 . "$_EXEC/acl.sh"
 
-page="$1"
+LIST=true DIFF=
+while [ $# -gt 0 ]; do case $1 in
+  --list)
+    LIST=true
+    shift 1
+    ;;
+  --no-list)
+    LIST=
+    shift 1
+    ;;
+  --diff)
+    DIFF=true
+    shift 1
+    ;;
+  --no-diff)
+    DIFF=
+    shift 1
+    ;;
+  *)page="$1"
+    shift 1
+    ;;
+esac; done
+
 page_abs="$(page_abs "$page")"
+page_default="${page_abs%:*/}" 
 
 if ! acl_read "$page_abs"; then
   return 0
-elif [ "$REV_PAGES" != true ]; then
-  printf '<div class="macro revisions error">GIT is not available to handle revisioning.</div>'
 fi
 
-printf '<ul class="macro revisions">\n'
+printf '<div class="macro revisions">\n'
+
+if [ "$REV_PAGES" != true ]; then
+  printf '<div class="error">GIT is not available to handle revisioning.</div>'
+fi
+
+if [ "$LIST" = true ]; then
+  printf '<ul>\n'
   IFS="        "
   { git -C "$_DATA" log --date=format:"%a, %x %H:%M" \
                       --pretty=format:"%h      %cd     %s" \
@@ -24,4 +52,26 @@ printf '<ul class="macro revisions">\n'
     printf '<li><span class="hash"><a href="%s">%s</a></span><span class="date">%s</span><span class="user">%s</span></li>\n' \
       "$(HTML "${page%/}/[revision]/$hash")" "$(HTML "$hash")" "$(HTML "$date")" "$(HTML "$user")"
   done
-printf '</ul>\n'
+  printf '</ul>\n'
+fi
+
+if [ "$DIFF" = true -a "$LANGUAGE_DEFAULT" -a "$page_default" != "$page_abs" ]; then
+  commit="$(git -C "$_DATA" log --pretty=format:%H -- "pages${page_abs}#page.md" |head -n1)"
+  printf '<section class="diff"><h2>Latest changes to original language page</h2>'
+  git -C "$_DATA" diff -U3 "$commit" -- "pages${page_default}#page.md" |tail -n+5 \
+  | while read -r diff; do case $diff in
+    @@\ *\ @@*)
+        line="${diff#@@ * @@}"
+        num="${diff%"${line}"}"
+        printf '<span class="linenum">%s</span>\n' "$(HTML "$num")"
+        printf '<span class="line">%s</span>\n' "$(HTML "$line")"
+        ;;
+    -*) printf '<span class="linedel">%s</span>\n' "$(HTML "$diff")";;
+    +*) printf '<span class="lineadd">%s</span>\n' "$(HTML "$diff")";;
+    \ *) printf '<span class="line">%s</span>\n' "$(HTML "$diff")";;
+    \\\ *) printf '<span class="linenote">%s</span>\n' "$(HTML "$diff")";;
+  esac; done
+  printf '</section>'
+fi
+
+printf '</div>\n'
index d35e1bf6ba26502cbee48061e01659924ba1b5a1..c4ebf6e447d4b36d30290e383b942ed0eb201024 100644 (file)
@@ -193,6 +193,18 @@ body[id$="/[newpage]"] textarea {
   margin-right: 1em;
 }
 
+.revisions .diff span {
+  font-family: monospace;
+  display: block;
+  white-space: pre;
+  line-height: 1.375em;
+}
+.revisions .diff span.linenum { color: #D60; }
+.revisions .diff span.linedel { color: #A00; }
+.revisions .diff span.lineadd { color: #0A0; }
+.revisions .diff span.linenote { color: #AAA; }
+
+
 [id$="/[attachment]"] input[type=radio].tab ~ div.tab {
   display: block;
   padding-top: 1em;