]> git.plutz.net Git - shellwiki/commitdiff
introduce tags and tag filtering
authorPaul Hänsch <paul@plutz.net>
Tue, 19 Sep 2023 16:38:24 +0000 (18:38 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 19 Sep 2023 16:38:24 +0000 (18:38 +0200)
macros/tag [new file with mode: 0755]
tools.sh

diff --git a/macros/tag b/macros/tag
new file mode 100755 (executable)
index 0000000..2731ad9
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. "$_EXEC/cgilite/storage.sh"
+
+_DATE="$(date +%s)"
+
+mkdir -p "$_DATA"/tags
+
+printf '<ul class="macro tag">\n'
+for tag in "$@"; do
+  tag="$(printf %s "$tag" |awk '{ sub(/^#/, ""); gsub(/[^[:alnum:]]/, "_"); print toupper($0); }')"
+  DBM "${_DATA}/tags/${tag}" set "$PATH_INFO" "$_DATE"
+  printf '<li class="tag">#%s</li>\n' "$tag"
+done
+printf '</ul>\n'
index 4f7bc2525ff8e49cf5c5d5c72d252b8f49832be0..57ae8274cc6d1fde2a5be157531734c8b246832d 100755 (executable)
--- a/tools.sh
+++ b/tools.sh
@@ -17,6 +17,8 @@ include_tools="$0"
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
+. "${_EXEC}/cgilite/storage.sh"
+
 md(){
   local parser
 
@@ -147,3 +149,19 @@ page_abs(){
     *)  PATH "${PATH_INFO%/*}/${1%/}/";;
   esac
 }
+
+has_tags() {
+  local page="$(page_abs "$1")"; shift 1;
+  local tdir="$_DATA/tags" tag dt df
+
+  for tag in "$@"; do
+    tag="$(printf %s "$tag" |awk '{ sub(/^#/, ""); gsub(/[^[:alnum:]]/, "_"); print toupper($0); }')"
+    dt="$(DBM "${tdir}/${tag}" get "${page}")" || return 1
+    df="$(stat -c %Y "$(mdfile "$page")")" || return 1
+    if [ "$df" -gt "$dt" ]; then
+      DBM "${tdir}/${tag}" remove "${page}"
+      return 1
+    fi
+  done
+  return 0
+}