]> git.plutz.net Git - shellwiki/blobdiff - macros/include
allow negative tag selection
[shellwiki] / macros / include
index f3005849cb2c9be5bdba8ceb57bca2e73031a5b0..1fd734cbe5214b0a83fd73107c85a1f345d61064 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright 2022 Paul Hänsch
+# Copyright 2022 - 2023 Paul Hänsch
 # 
 # Permission to use, copy, modify, and/or distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -18,8 +18,9 @@
 . "$_EXEC/acl.sh"
 . "$_EXEC/tools.sh"
 
-from='1'; to='$'; rev=''; items='$'; hl=0; link='true'
+from='1'; to='$'; rev=''; items='$'; hl=0; link='true'; depth=0; tags=''; ntags=''; page='';
 
+set -- "$@" --
 while [ $# -gt 0 ]; do case $1 in
   --from) from="$2"; shift 2;;
   from=*) from="${1#*=}"; shift 1;;
@@ -30,7 +31,11 @@ while [ $# -gt 0 ]; do case $1 in
   --rev|--reverse) rev="-r"; shift 1;;
   --nolink) link=""; shift 1;;
   --hl|-hl) hl=$2; shift 2;;
-  *) page="$1"; shift 1;;
+  --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
 
 if ! printf %s\\n "$from" |grep -qEx '[0-9]+|/([^/\\]|\\/|\\.)*/'; then
@@ -46,13 +51,19 @@ if ! printf %s\\n "$items" |grep -qEx '\$|[0-9]+'; then
   exit 1
 fi
 
-page_glob "$page" \
+for page in "$@"; do
+  page_glob "$page" "$depth"
+done \
 | sort $rev \
 | sed "${items}q" \
 | while read glob; do
   page="$(page_abs "$glob")"
-  acl_read "$page" || continue
   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")"
   refpfx="$(printf %s\\n "$hglob" |sed 's;[\;&\;];\\&;g')"
   [ "$link" ] \