]> git.mdlowis.com Git - projs/awiki.git/commitdiff
added tag count to the datalist entries
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 16 Jun 2020 10:57:18 +0000 (06:57 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 16 Jun 2020 10:57:18 +0000 (06:57 -0400)
awiki.rb

index a44f89fe63dd10f3dfda8403586c3ddb3566ccc0..b58ef9c3de8e5eaddef052be69330ffb525b3861 100755 (executable)
--- a/awiki.rb
+++ b/awiki.rb
@@ -182,15 +182,19 @@ def gensitemap()
     f.puts "<label>Search Tags:</label><input id=\"filterTags\" list=\"allTags\"/>"
     f.puts "<div id=\"activeTags\"></div></p>"
     f.puts "<ul id=\"pages\">"
-    tags = []
+    tags = {}
     $db[:pages].values.filter{|h| h[:title] }.sort_by{|h| h[:title] }.each do |p|
-      tags += p[:tags]
+      (p[:tags] || []).each do |t|
+        tags[t] ||= 0
+        tags[t] += 1
+      end
       f.puts "<li><a href=\"#{web_path(p[:path])}\" data-tags=\"#{p[:tags].join(" ")}\">#{p[:title]}</a></li>"
     end
     f.puts "</ul>"
     f.puts "\n\n<p>#{SEARCH_SCRIPT}</p>"
-    f.puts "<p><datalist id =\"allTags\">"
-    tags.sort.uniq.each {|t| f.puts "<option value=\"#{t}\"/>" }
+    f.puts "<p><datalist id=\"allTags\">"
+    tags.to_a.sort_by{|e| e[0] }.each {|t|
+      f.puts "<option value=\"#{t[0]}\">#{t[0]}\t(#{t[1]})</option>" }
     f.puts "</datalist></p>"
   end
 end
@@ -295,4 +299,4 @@ if ARGV.length > 0 then
   $server.start
 end
 
-#pp $db
\ No newline at end of file
+#pp $db