]> git.plutz.net Git - serve0/commitdiff
avoid multiple reordering of tags
authorPaul Hänsch <paul@plutz.net>
Tue, 22 Feb 2022 16:58:03 +0000 (17:58 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 22 Feb 2022 16:58:03 +0000 (17:58 +0100)
multitag.sh
widgets.sh

index d928e459d8596de0e23def22731d7e44682e83cb..12117cdf86ea852b7ea430a5aedd00c9f8eb4969 100755 (executable)
@@ -51,8 +51,6 @@ done
 
 ( if [ $(POST_COUNT select) -gt 0 ]; then
     taglist >"$c_tags.$$"
-    tclist "$(cat "$c_tags.$$")" >"$c_tagcategories.$$"
     mv -- "$c_tags.$$" "$c_tags"
-    mv -- "$c_tagcategories.$$" "$c_tagcategories"
   fi &
 ) &
index 26d755fb4301e3676b973cad186edfc41f13af8f..46fdbf65525d32b017d47f2bdb4d4d2f71218903 100755 (executable)
@@ -20,11 +20,13 @@ taglist(){
   | UNSTRING | HTML \
   | sed -E 's;&#x0A\;;\n;g; s;\n+;\n;g;'
 }
-
-tclist(){
-  printf %s "$*" \
-  | sed -rn '/:/s;^-?([^:]+):.*$;\1;p' \
-  |sort -u
+tagorder(){
+  printf '*\n%s\n$\n' "$w_tagcategories" \
+  | while read -r category; do
+    printf '%s\n' "$w_tags" \
+    | { [ "$category" = '*' ] && grep -avF ':' || grep -awF "${category}"; } \
+    | { sed -u 10q; sort; }
+  done
 }
 
 c_tags="$_DATA/.index/tags.cache";
@@ -33,13 +35,12 @@ if [ ! -s "$c_tags" ]; then
   mv "$c_tags.$$" "$c_tags"
 fi
 w_tags="$(cat "$c_tags")"
-
-c_tagcategories="$_DATA/.index/tagcategories.cache"
-if [ ! -s "$c_tagcategories" ]; then
-  tclist "$w_tags" >"$c_tagcategories.$$"
-  mv "$c_tagcategories.$$" "$c_tagcategories"
-fi
-w_tagcategories="$(cat "$c_tagcategories")"
+w_tagcategories="$(
+  printf %s "$w_tags" \
+  | sed -rn '/:/s;^-?([^:]+):.*$;\1;p' \
+  |sort -u
+)"
+w_tags="$(tagorder)"
 
 [ "$ORDER" = Name   ] && w_coname=checked
 [ "$ORDER" = Date   ] && w_codate=checked
@@ -194,7 +195,6 @@ w_advsearch(){
 
       printf '%s\n' "$w_tags" \
       | { [ "$category" = '*' ] && grep -avF ':' || grep -awF "${category}"; } \
-      | { sed -u 10q; sort; } \
       | while read -r tag; do
         [ "$tag" ] || continue
         t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked
@@ -244,7 +244,6 @@ w_tagging(){
     printf '[fieldset [legend %s:][div .tagselect\n' "$category"
     printf %s "$w_tags" \
     | { [ "$category" = 'Tags' ] && grep -avF ':' || grep -awF "${category}"; } \
-    | { sed -u 10q; sort; } \
     | while read -r tag; do
       [ "$tag" ] || continue
       d="${tag#-}"; d="${d#*:}"