From 21b87390a05a69a53d5c66e385443d1397273f1a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sat, 21 Jul 2018 00:42:35 +0200 Subject: [PATCH] sort tags by frequency --- widgets.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/widgets.sh b/widgets.sh index cb5cf97..dd34bc0 100644 --- a/widgets.sh +++ b/widgets.sh @@ -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;:\;;:;g; s; \;;\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;:\;;:;g; s; \;;\n;g;')" +w_tags="$( printf %s "$w_tags" |HTML |sed 's;:\;;:;g; s; \;;\n;g;')" [ "$ORDER" = Name ] && w_coname=checked [ "$ORDER" = Date ] && w_codate=checked -- 2.39.2