constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 6c473d044ccbb13e055ad10da6ad03d292f9ff91
parent c748d1d4dc6de27ccdf9f0d74839d7ed0c568bd8
Author: Dan Callaghan <djc@djc.id.au>
Date:   Tue, 16 Sep 2008 22:15:48 +1000

tag cloud

--HG--
rename : templates/single.xml => templates/tag_cloud.xml

Diffstat:
MTODO | 1-
Mapp.py | 13+++++++++++++
Astatic/css/tag_cloud.css | 19+++++++++++++++++++
Mtemplates/multiple.xml | 2+-
Atemplates/tag_cloud.xml | 24++++++++++++++++++++++++
5 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/TODO b/TODO
@@ -12,7 +12,6 @@
   ...
 - pings, e.g. http://www.technorati.com/developers/ping/
 - http://www.pell.portland.or.us/~orc/Code/markdown/ or http://github.com/jgm/peg-markdown/tree/master
-- tag cloud at /+tags/
 - cycling log
   - initially link to Nokia
   - eventually write own GPS tracker ...
diff --git a/app.py b/app.py
@@ -21,6 +21,7 @@ template_loader = TemplateLoader(
 class Constance(RegexApplication):
 
     urls = [(r'^$', 'index'), 
+            (r'^\+tags/$', 'tag_cloud'), 
             (r'^\+tags/(.+)$', 'tag'), 
             (r'^\+reading/?$', 'reading'), 
             (r'^([^+/][^/]*)/?$', 'post'), 
@@ -65,6 +66,18 @@ class Constance(RegexApplication):
         else:
             raise PageNotFound('Unknown format %r' % format)
     
+    def tag_cloud(self):
+        tag_freqs = {}
+        for entry in self.blog_entries:
+            for tag in entry.tags:
+                tag_freqs[tag] = tag_freqs.get(tag, 0) + 1
+        rendered = template_loader.load('tag_cloud.xml').generate(
+                config=self.config, 
+                environ=self.request.environ, 
+                tag_freqs=tag_freqs
+                ).render('xhtml')
+        return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
+    
     def post(self, id):
         id = id.decode(self.charset) # shouldn't Colubrid do this?
         try:
diff --git a/static/css/tag_cloud.css b/static/css/tag_cloud.css
@@ -0,0 +1,19 @@
+ol#tagcloud {
+    margin: 0;
+    padding: 0;
+    line-height: 4ex;
+}
+ol#tagcloud li {
+    display: inline;
+    list-style: none;
+    margin-right: 0.75em;
+}
+ol#tagcloud a {
+    white-space: nowrap;
+}
+ol#tagcloud .frequency {
+    /* http://css-discuss.incutio.com/?page=OffLeft */
+    position: absolute;
+    left: -1000px;
+    width: 100px;
+}
diff --git a/templates/multiple.xml b/templates/multiple.xml
@@ -16,7 +16,7 @@
 </head>
 <body>
 
-<h2 class="archives" py:if="title">Archive of ${title}</h2>
+<h2 py:if="title">Archive of ${title}</h2>
 
 <py:for each="entry in (defined('offset') and sorted_entries[offset:offset + config.getint('global', 'entries_per_page')] or sorted_entries)">
     ${show_entry(entry, show_comments=False)}
diff --git a/templates/tag_cloud.xml b/templates/tag_cloud.xml
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude"
+      lang="en-AU">
+<xi:include href="_commonwrapper.xml" />
+
+<head>
+    <title>Tag cloud</title>
+    <link rel="stylesheet" type="text/css" href="${environ.get('SCRIPT_NAME', '')}/static/css/tag_cloud.css" />
+</head>
+<body>
+
+<h2>Tag cloud</h2>
+
+<ol id="tagcloud">
+    <li py:for="tag, freq in sorted(tag_freqs.iteritems(), key=lambda (t, f): t.lower())">
+        <a rel="tag" href="${environ.get('SCRIPT_NAME', '')}/+tags/${tag}" style="font-size: ${0.8 + (freq / 10.)}em;">${tag}</a>
+        <span class="frequency">(used ${freq} times)</span>
+    </li>
+</ol>
+
+</body>
+</html>