X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=pages%2Fcommon.sh;h=4242aab3807ae9738ba86f4a79d6ad42bab84762;hb=30ac844acd16c48c632232285259a2fc449a58ce;hp=cb4117b5a9949fae419fdb1c856302198a608fda;hpb=47b905d14103c01625d16fe557e63e34317c6453;p=serve0 diff --git a/pages/common.sh b/pages/common.sh index cb4117b..4242aab 100755 --- a/pages/common.sh +++ b/pages/common.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2014, 2015 Paul Hänsch +# Copyright 2014 - 2016 Paul Hänsch # # This file is part of Serve0. # @@ -28,19 +28,47 @@ page_link='' [ -n "$order" ] && page_link="${page_link}o=${order}&" [ -n "$search" ] && page_link="${page_link}s=${search}&" [ -n "$filter" ] && page_link="${page_link}f=${filter}&" -page_prev="${page_link}pn=$([ "$page" -le "$pagesize" ] && echo 1 || echo $(($page - $pagesize)) )" +[ "$page" -le "$pagesize" ] && page_prev="${page_link}pn=1" || page_prev="${page_link}pn=$(($page - $pagesize))" 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 + printf \\n + ) | (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 + printf \\n + ) | 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(){ - echo none + printf none\\n printf %s "$taglist" |sed -rn 's;^([^:]+):.*$;\1;p' |sort -u }