From 926ffb4fb96b4def0a1144c7c1ec2e46891d271e Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 23 Oct 2015 14:14:14 +0000 Subject: [PATCH] prefer most used tags in taglist svn path=/trunk/; revision=98 --- pages/common.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/pages/common.sh b/pages/common.sh index cb4117b..ecf16c2 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -33,10 +33,38 @@ page_next="${page_link}pn=$(($page + $pagesize))" page_this="${page_link}pn=$page" taglist=$( - [ -r ${_DATA}/cache/taglist ] && cat ${_DATA}/cache/taglist ||\ - for each in ${_DATA}/meta/*.meta; do +if [ -r ${_DATA}/cache/taglist ]; then + cat ${_DATA}/cache/taglist +else + truncate -s0 ${_DATA}/cache/taglist + truncate -s0 ${_DATA}/cache/tagnorm + (for each in ${_DATA}/meta/*.meta; do sed -n '2s:|:\n:gp' "$each" - done |sort -u |grep -xv '' |tee ${_DATA}/cache/taglist + done \ + | sort + echo + ) | (while read tag; do + if [ "$tag" = "$lasttag" ]; then + tagcount=$(( ${tagcount:-0} + 1 )) + else + [ -n "$lasttag" ] && printf %s\\t%s\\n "$tagcount" "$lasttag" + tagcount=1 + fi + lasttag="$tag" + done \ + | sort -rn + echo + ) | while read x tag; do + topcnt=$(grep "${tag%%:*}" ${_DATA}/cache/taglist |wc -l) + [ $topcnt -lt 10 ] \ + && printf %s\\n "$tag" >>${_DATA}/cache/taglist \ + || printf %s\\n "$tag" >>${_DATA}/cache/tagnorm + done + cat ${_DATA}/cache/taglist + sort ${_DATA}/cache/tagnorm \ + | tee -a ${_DATA}/cache/taglist + rm ${_DATA}/cache/tagnorm +fi ) list_categories(){ -- 2.39.2