]> git.plutz.net Git - serve0/blobdiff - widgets.sh
sort tags by frequency
[serve0] / widgets.sh
index 9bb6d93e9a8ff7ffd5108e7479383a58450f1b31..dd34bc0b627ae68b395d235fa0b024996cc45568 100644 (file)
@@ -7,12 +7,26 @@ include_widgets="$0"
 
 w_refuri="$(URL "$PATH_INFO")?$(HTML "$QUERY_STRING")"
 
-w_tags="$(find "$_DATA/" -path '*/.index/meta' -print0 \
-        | xargs -r0 sed -r '
-          s;^.*\t.*\t.*\ttags=(.*)\tcomment=.*\t.*\r$;\1;;
-          s;,;\n;g;'"$UNSTRING" \
-        | sort -u |HTML |sed 's;&#58\;;:;g; s;&#10\;;\n;g;')"
-w_tagcategories="$(printf %s "$w_tags" | cut -sd: -f1 | uniq)"
+w_tags="$( {
+  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
+    [ "$tag" = "$otag" ] \
+    && cn=$((${cn:-0} + 1)) \
+    || {
+      printf "%i       %s\n" "$cn" "$otag"
+      cn=1
+    }
+    otag="$tag"
+  done
+  printf "%i   %s\n" "$cn" "$otag"
+} |sort -rn |cut -f2- )"
+w_tagcategories="$(printf %s "$w_tags" | cut -sd: -f1 | sort -u \
+                   |HTML |sed 's;&#58\;;:;g; s;&#10\;;\n;g;')"
+w_tags="$( printf %s "$w_tags" |HTML |sed 's;&#58\;;:;g; s;&#10\;;\n;g;')"
 
 [ "$ORDER" = Name   ] && w_coname=checked
 [ "$ORDER" = Date   ] && w_codate=checked
@@ -61,7 +75,7 @@ w_bookmarks(){
             [a .link target=blank href="?o=Date&s=%s&f=%s" by Date]
             [a .link target=blank href="?o=Length&s=%s&f=%s" by Length]
             [br]' \
-            "$(HTML "$name")" \
+            "$(HTML "$name" |sed 's;&#44\;;&[wbr];g;')" \
             "$search" "$filter" \
             "$search" "$filter" \
             "$search" "$filter"