]> git.plutz.net Git - webtxt/commitdiff
list recent pages; git revisioning
authorPaul Hänsch <paul@plutz.net>
Fri, 19 Mar 2021 13:18:45 +0000 (14:18 +0100)
committerPaul Hänsch <paul@plutz.net>
Fri, 19 Mar 2021 13:18:45 +0000 (14:18 +0100)
index.cgi
webnote.css

index da1814251b310825d1db2205c400ac63ccc63de6..32f1418ba05909631723e1e3a87378f174ee6713 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-_EXEC="${_EXEC:-.}"
+_EXEC="${_EXEC:-${0%/*}/}"
 _DATA="${_DATA:-.}"
 
 . "$_EXEC"/cgilite/cgilite.sh
@@ -8,6 +8,8 @@ _DATA="${_DATA:-.}"
 . "$_EXEC"/cgilite/file.sh
 . "$_EXEC"/session_lock.sh
 
+git init "$_DATA"
+
 yield_page(){
   page="$1"
   printf '%s\r\n' 'Content-Type: text/html; charset=utf-8' \
@@ -32,10 +34,12 @@ case ${PATH_INFO##*/} in
   webnote.css) FILE "$_EXEC/webnote.css";;
   '') yield_page <<-EOF
        [form .new action=new [button type=submit New Note]
-         [ul .recent
-         $({ COOKIE pages; echo; } |tr \  \\n |while read page; do
-           [ "$(printf %s "$page" |checkid)" ] && printf '[li [a href="./%s" . %s]]' "$page" "$page"
-         done)]
+          $(if [ "$(COOKIE pages)" ]; then
+           printf '[h2 Recent Pages][ul .recent'
+           { COOKIE pages; echo; } |tr \  \\n |while read page; do
+             [ "$(printf %s "$page" |checkid)" ] && printf '[li [a href="./%s" . %s]]' "$page" "$page"
+           done
+           fi)]
        ]
        EOF
     return 0
@@ -43,6 +47,8 @@ case ${PATH_INFO##*/} in
   new)
     newid="$(timeid)"
     touch "$_DATA/$newid"
+    git -C "$_DATA" add "$newid"
+    git -C "$_DATA" commit -m "new note \"${newid}\"" "$newid"
     REDIRECT "./$newid"
     ;;
 esac
@@ -50,7 +56,7 @@ esac
 doc="$_DATA/$(printf %s ${PATH_INFO##*/} |checkid)"
 
 if [ ! -f "$doc" ]; then
-  REDIRECT "${PATH_INFO%%/*}/"
+  REDIRECT "${PATH_INFO%/*}/"
   return 0
 fi
 
@@ -80,6 +86,7 @@ fi
     if temp=$(CHECK_SLOCK "$doc"); then
       RELEASE_SLOCK "$doc"
       POST document >"${doc}"
+      git -C "$_DATA" commit -m "update note ${doc##*/} \"$(sed '1{s;\r;;; q;}' "$doc")\"" "${doc##*/}" >/dev/null
       REDIRECT "$PATH_INFO"
     else
       yield_page <<-EOF
index e87795e7bc9fb569328760565fdc6c7b357dcbb6..eb2306d0860ec213eee4a70006fb06b37a08a69e 100644 (file)
@@ -22,10 +22,11 @@ form.new {
 
 .new button {
   display: block;
-  margin: auto;
+  margin-left: auto;
+  margin-right: auto;
 }
 
-.recent {
+ul.recent {
   display: inline-block;
   text-align: left;
 }