From: Paul Hänsch Date: Tue, 19 Sep 2023 16:38:24 +0000 (+0200) Subject: introduce tags and tag filtering X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=52cf0a6d2568c6c45a677c1f9038ab42ac7801ac;p=shellwiki introduce tags and tag filtering --- diff --git a/macros/tag b/macros/tag new file mode 100755 index 0000000..2731ad9 --- /dev/null +++ b/macros/tag @@ -0,0 +1,15 @@ +#!/bin/sh + +. "$_EXEC/cgilite/storage.sh" + +_DATE="$(date +%s)" + +mkdir -p "$_DATA"/tags + +printf '\n' diff --git a/tools.sh b/tools.sh index 4f7bc25..57ae827 100755 --- 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 +}