]> git.plutz.net Git - shellwiki/commitdiff
Taglist and tag cloud
authorPaul Hänsch <paul@plutz.net>
Tue, 19 Mar 2024 09:59:08 +0000 (10:59 +0100)
committerPaul Hänsch <paul@plutz.net>
Tue, 19 Mar 2024 09:59:08 +0000 (10:59 +0100)
macros/taglist [new file with mode: 0755]
themes/default.css

diff --git a/macros/taglist b/macros/taglist
new file mode 100755 (executable)
index 0000000..576655b
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+# Copyright 2024 Paul Hänsch
+# 
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+# 
+# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+. "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/cgilite/storage.sh"
+. "$_EXEC/cgilite/db23.sh"
+
+cloud='' link=''
+while [ $# -gt 0 ]; do case $1 in
+  --cloud) cloud=true; shift 1;;
+  --link)  link=true; shift 1;;
+esac; done
+
+taglist="$(
+  max=0
+  for tagfile in "$_DATA"/tags/*; do
+    tag="${tagfile##*/}"
+    [ "$tag" = "*" ] && break
+  
+    n=0; while read -r page date; do
+      if ! pdate="$(DB3 get "$page")"; then
+        if pdate="$(stat -c %Y "$_DATA/pages/$(UNSTRING "$page")/#page.md" )"; then
+          DB3 set "$page" "$pdate"
+        else
+          debug "Remove $page from $tag"
+          # DBM "$tagfile" remove "$(UNSTRING "$page")"
+          date=0
+        fi
+      fi
+      [ "$date" -ge "$pdate" ] && n=$((n + 1))
+    done <"$tagfile"
+    if [ $n -gt 0 ]; then
+      printf '%i       %i      %s\n' "$RANDOM" "$n" "$tag"
+    else
+      debug "Removing tag: $tagfile" # && rm -- "$tagfile"
+    fi
+    [ $n -gt $max ] && max="$n"
+  done
+  printf "%i\n" "$max"
+)"
+max="${taglist##*${BR}}"
+taglist="${taglist%${BR}*}"
+
+if [ "$taglist" ]; then
+  [ "$cloud" ] && printf '<ul class="macro taglist cloud">\n' \
+               || printf '<ul class="macro taglist">\n'
+  printf %s\\n "$taglist" \
+  | { [ "$cloud" ] && sort -n || sort -k 3; } \
+  | while read -r junk inc tag; do
+    if [ "$link" ]; then
+      printf '<li class=tag inc=%i rel=%i ><a href="./[search]?q=%s">#%s</a></li>\n' \
+             "$inc" "$((9 * inc / max))" "$(URL "$tag")" "$(HTML "$tag")"
+    else
+      printf '<li class=tag inc=%i rel=%i >#%s</li>\n' \
+             "$inc" "$((9 * inc / max))" "$(HTML "$tag")"
+    fi
+  done
+  printf '</ul>\n'
+fi
index f8c28acf3419b9f1416e38859e4a49bf1b20b412..e0f7022182b509dfb54737561a760aaf70ba51fd 100644 (file)
@@ -412,6 +412,22 @@ ul.macro.tag { padding: 0; }
 }
 
 
+.macro.taglist li {
+  display: inline-block;
+  margin-right: .75em;
+}
+.macro.taglist.cloud li[rel="0"] { font-size: 6pt; }
+.macro.taglist.cloud li[rel="1"] { font-size: 7.5pt; }
+.macro.taglist.cloud li[rel="2"] { font-size: 9pt; }
+.macro.taglist.cloud li[rel="3"] { font-size: 11.5pt; }
+.macro.taglist.cloud li[rel="4"] { font-size: 13pt; }
+.macro.taglist.cloud li[rel="5"] { font-size: 14.5pt; }
+.macro.taglist.cloud li[rel="6"] { font-size: 16pt; }
+.macro.taglist.cloud li[rel="7"] { font-size: 17.5pt; }
+.macro.taglist.cloud li[rel="8"] { font-size: 19pt; }
+.macro.taglist.cloud li[rel="9"] { font-size: 21.5pt; }
+
+
 .macro.changes td .date {
   display: block;
   font-size: .75em;