]> git.plutz.net Git - serve0/commitdiff
generate tagging section from cached order
authorPaul Hänsch <paul@plutz.net>
Tue, 22 Feb 2022 18:32:09 +0000 (19:32 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 22 Feb 2022 18:32:09 +0000 (19:32 +0100)
widgets.sh

index 46fdbf65525d32b017d47f2bdb4d4d2f71218903..23afd9d440ba6ffbf411faaffcd628f58634403d 100755 (executable)
@@ -230,7 +230,7 @@ w_delete(){
 }
 
 w_tagging(){
-  local tag category d
+  local tctag oldcat category tag
 
   cat <<-EOF
        [a href="#multitag" Add Tags / Remove Tags]
@@ -238,19 +238,26 @@ w_tagging(){
          [a href="#" X]
        EOF
 
-  printf 'Tags\n%s\n' "$w_tagcategories" \
-  | while read -r category; do
-    [ "$category" ] || continue
-    printf '[fieldset [legend %s:][div .tagselect\n' "$category"
-    printf %s "$w_tags" \
-    | { [ "$category" = 'Tags' ] && grep -avF ':' || grep -awF "${category}"; } \
-    | while read -r tag; do
-      [ "$tag" ] || continue
-      d="${tag#-}"; d="${d#*:}"
-      printf '[label [checkbox "tag" "%s"] %s]\n' "$tag" "$d"
-    done
-    printf ']]'
+  oldcat="Tags"
+  printf '[fieldset [legend %s:][div .tagselect\n' "Tags"
+  printf '%s\n' "$w_tags" \
+  | while read tctag; do
+    [ "$tctag" ] || continue
+    category="${tctag#-}"; category="${category%%:*}"
+    tag="${tctag#-}"; tag="${tag#*:}"
+
+    [ "${tag}" = "${tctag#-}" ] \
+    && category="Tags"
+
+    if [ "$category" != "$oldcat" ]; then
+      printf ']]'
+      printf '[fieldset [legend %s:][div .tagselect\n' "$category"
+    fi
+    printf '[label [checkbox "tag" "%s"] %s]\n' "$tctag" "$tag"
+
+    oldcat="$category"
   done
+  printf ']]'
 
   cat <<-EOF
          [fieldset [legend New:][textarea name=newtag\n]