]> git.plutz.net Git - serve0/blobdiff - widgets.sh
display either tagging or indexer
[serve0] / widgets.sh
index 0474fa5ea7f07ce669995f6caaf3ed4288438c0f..446b5d2edfafe6d1078dbcaccb8005db8ff08e56 100644 (file)
@@ -21,20 +21,20 @@ w_ascii='
   s-s-s-g; s-t-t-g; s-u-u-g; s-v-v-g; s-w-w-g; s-x-x-g;
   s-y-y-g; s-z-z-g;
   s---\--g; s-/-/-g; s-/-/-g; s-:-:-g; s-=-=-g; s-@-@-g;
-  s-_-_-g; s-~-~-g;              s-- -g; s-^-^-g; s-|-|-g;
+  s-_-_-g; s-~-~-g;              s- - -g; s-^-^-g; s-|-|-g;
 '
 
 w_tags="$_DATA/.index/tags.cache"; w_tagcategories="$_DATA/.index/tagcategories.cache"
 if [ ! -f "$w_tags" -o ! -f "$w_tagcategories" ] \
-   || [ "$(find "$_DATA/" -path '*/.index/meta' -newer "$w_tags" -quit)" ]
+   || [ "$(find "$_DATA/" -path '*/.index/meta' -newer "$w_tags")" ]
   then
   w_tags="$( { local cn=1
     find "$_DATA/" -path '*/.index/meta' -print0 \
     | xargs -r0 sed -r '
       s;^.*\t.*\t.*\ttags=(.*)\tcomment=.*\t.*\r$;\1;;
       s;,;\n;g;'"$UNSTRING" \
-    | sort \
-    | while read tag; do
+    | { sort; printf '\n'; } \
+    | while read -r tag; do
       [ "$tag" = "$otag" ] \
       && cn=$((cn + 1)) \
       || {
@@ -43,8 +43,7 @@ if [ ! -f "$w_tags" -o ! -f "$w_tagcategories" ] \
       }
       otag="$tag"
     done
-    printf "%i %s\n" "$cn" "$otag"
-  } |sort -rn |cut -f2- |HTML |sed "$w_ascii s-
-\n-g;" |tee "$w_tags" )"
+  } |sort -rn |cut -f2- |HTML |sed "$w_ascii s-
-\n-g; s;\n\n;\n;g;" |tee "$w_tags" )"
   w_tagcategories="$(printf %s "$w_tags" \
                      | cut -sd: -f1 |sort -u \
                      | tee "$w_tagcategories" )"
@@ -148,7 +147,7 @@ w_prefs(){
 }
 
 w_index(){
-  [ -d "$_DATA/$ITEM/.index" ] || printf '
+  [ -d "$_DATA/$ITEM/.index" ] && return 1 || printf '
   [form #index method="POST" action="?a=spawnindex"
     [hidden "ref" "%s"]
     [label Set up for Index view: ]
@@ -156,6 +155,7 @@ w_index(){
     [submit "spawn" "spawn" Set up]
   ]
   ' "$w_refuri"
+  return 0
 }
 
 w_advsearch(){
@@ -196,9 +196,13 @@ w_advsearch(){
               $n "$category" "$t" "$lbid" "$lbid" "$category" $n
 
       printf '%s\n' "$w_tags" \
-      | { [ "$category" = '*' ] && grep -avF ':' |grep -avxF '' || grep -awF "${category}"; } \
-      | { for n in 1 2 3 4 5 6 7 8 9 0; do line; done; sort; } \
-      | while read -r tag; do
+      | { [ "$category" = '*' ] && grep -avF ':' || grep -awF "${category}"; } \
+      | { for n in 1 2 3 4 5 6 7 8 9 0; do
+          read -r line && printf '%s\n' "$line" || break;
+          done;  # path 10 lines through without modification
+          sort;  # and sort remaining lines
+      } | while read -r tag; do
+        [ "$tag" ] || continue
         t=''; [ ! "${f%%*|${tag}|*}" ] && t=checked
         printf '[option %s value="%s"\n%s]' "$t" "$tag" "${tag#*:}"
       done
@@ -228,9 +232,13 @@ w_tagging(){
   | while read -r category; do
     printf '[fieldset [legend %s:][select name=tag size=4 multiple' "$category"
     printf %s "$w_tags" \
-    | { [ "$category" = 'Tags' ] && grep -avF ':' | grep -avxF '' || grep -awF "${category}"; } \
-    | { for n in 1 2 3 4 5 6 7 8 9 0; do line; done; sort; } \
-    | while read -r tag; do
+    | { [ "$category" = 'Tags' ] && grep -avF ':' || grep -awF "${category}"; } \
+    | { for n in 1 2 3 4 5 6 7 8 9 0; do
+        read -r line && printf '%s\n' "$line" || break
+        done;
+        sort;
+    } | while read -r tag; do
+      [ "$tag" ] || continue
       printf '[option value="%s"\n%s]' "$tag" "${tag#*:}"
     done
     printf ']]'