From e5ea4373a0510820e542e2b4eed63ff64211da9a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 14 Nov 2023 21:48:10 +0100 Subject: [PATCH] allow negative tag selection --- macros/include | 4 +++- macros/pagelist | 6 ++++-- tools.sh | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/macros/include b/macros/include index fbc2fff..1fd734c 100755 --- a/macros/include +++ b/macros/include @@ -18,7 +18,7 @@ . "$_EXEC/acl.sh" . "$_EXEC/tools.sh" -from='1'; to='$'; rev=''; items='$'; hl=0; link='true'; depth=0; tags=''; page=''; +from='1'; to='$'; rev=''; items='$'; hl=0; link='true'; depth=0; tags=''; ntags=''; page=''; set -- "$@" -- while [ $# -gt 0 ]; do case $1 in @@ -33,6 +33,7 @@ while [ $# -gt 0 ]; do case $1 in --hl|-hl) hl=$2; shift 2;; --depth) depth=$2; shift 2;; \#*) tags="${tags}${tags:+ }${1}"; shift 1;; + \!*) ntags="${ntags}${ntags:+ }${1}"; shift 1;; --) shift 1; break;; *) set -- "$@" "$1"; shift 1;; esac; done @@ -60,6 +61,7 @@ done \ mdfile="$(mdfile "$page")" || continue acl_read "$page" || continue has_tags "$page" $tags || continue + has_tag "$page" $ntags && continue printf %s\\n "$INCLUDE_LIST" |grep -qxF "$page" && continue export INCLUDE_LIST="${INCLUDE_LIST}${INCLUDE_LIST:+${BR}}$page" hglob="$(HTML "$glob")" diff --git a/macros/pagelist b/macros/pagelist index 08764aa..ced89eb 100755 --- a/macros/pagelist +++ b/macros/pagelist @@ -18,7 +18,7 @@ . "$_EXEC/acl.sh" . "$_EXEC/tools.sh" -tags='' dir='' depth='' glob_system_pages=false +tags='' ntags='' dir='' depth='' glob_system_pages=false label='' labeltype='' altlabel='' cnt=0 set -- "$@" -- @@ -26,6 +26,7 @@ while [ $# -gt 0 ]; do case $1 in --system) glob_system_pages=true; shift 1;; --depth) depth="$2" shift 2;; \#*) tags="${tags}${tags:+ }${1###}"; shift 1;; + \!*) ntags="${ntags}${ntags:+ }${1##!}"; shift 1;; --h1|--h2|--h3|--h4|--h5|--h6|--label) labeltype="${1#--}" label="$2"; shift 2;; --alt-label) @@ -54,7 +55,8 @@ done \ if [ -f "$_DATA/pages/${pagedir}/#page.md" -o \ -f "$_EXEC/pages/${pagedir}/#page.md" ] \ && acl_read "$pagedir" \ - && has_tags "$pagedir" $tags + && has_tags "$pagedir" $tags \ + && ! has_tag "$pagedir" $ntags then [ "$cnt" -eq 0 -a "$label" ] \ && printf '<%s class="macro pagelist label">%s' \ diff --git a/tools.sh b/tools.sh index 57ae827..a298394 100755 --- a/tools.sh +++ b/tools.sh @@ -151,11 +151,12 @@ page_abs(){ } has_tags() { + # true if PAGE is tagges with all 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); }')" + 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 @@ -165,3 +166,22 @@ has_tags() { done return 0 } + +has_tag() { + # true if PAGE is tagged with any of 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}")" || continue + df="$(stat -c %Y "$(mdfile "$page")")" || return 1 + if [ "$df" -gt "$dt" ]; then + DBM "${tdir}/${tag}" remove "${page}" + continue + else + return 0 + fi + done + return 1 +} -- 2.39.2