constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 4b07b7e24b46c89c0d5ad9043ac626eec95c743c
parent aaca2940d4211c04c1513b11a76a34bfb0c82cc9
Author: Dan Callaghan <djc@djc.id.au>
Date:   Wed, 25 Aug 2010 22:19:05 +1000

show reading on homepage; fixed weird tag_list function; use local covers service instead of linking to LT directly

Diffstat:
Mhomepage.py | 2+-
Mtemplates/blog/entry.html | 2+-
Mtemplates/homepage/index.html | 37+++++++++++++++----------------------
Mtemplates/reading/reading.html | 2+-
Mviewutils.py | 5++---
5 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/homepage.py b/homepage.py
@@ -16,7 +16,7 @@ template_loader = genshi.template.TemplateLoader(
 def generate(dir, xslt, blog_entries, reading_entries):
     # index
     template = template_loader.load('index.html')
-    rendered = template.generate(blog_entries=blog_entries).render('xhtml')
+    rendered = template.generate(blog_entries=blog_entries, reading_entries=reading_entries).render('xhtml')
     transformed = str(xslt(lxml.etree.fromstring(rendered)))
     constance.output(os.path.join(dir, 'index.html'), transformed)
 
diff --git a/templates/blog/entry.html b/templates/blog/entry.html
@@ -18,7 +18,7 @@ from viewutils import tag_list
         <div class="date published">${item.publication_date.strftime(str('%-1d %b %Y'))}</div>
 
         <div py:if="item.tags" class="tags">
-            tagged: ${tag_list('', item.tags)} <!-- XXX script_name -->
+            tagged: ${tag_list(item.tags)}
         </div>
 
         <div class="entry-content">
diff --git a/templates/homepage/index.html b/templates/homepage/index.html
@@ -17,32 +17,25 @@ from viewutils import markdown, mini_markdown, tag_list
     <meta http-equiv="X-XRDS-Location" content="http://www.myopenid.com/xrds?username=djc.myopenid.com" />
 </head>
 
-<body py:with="sorted_blog_entries=sorted(blog_entries, key=lambda e: e.publication_date, reverse=True)">
-
-    <div class="item blog-entry" py:with="item = sorted_blog_entries[0]">
-
-        <h1 class="entry-title"><a href="http://www.djc.id.au/blog/${item.id}" rel="bookmark">${item.title}</a></h1>
+<body>
 
+    <h1>Recent blog entries</h1>
+    <div class="item blog-entry-stub" py:for="item in sorted(blog_entries, key=lambda e: e.publication_date, reverse=True)[:4]">
+        <h3 class="entry-title"><a href="blog/${item.id}">${item.title}</a></h3>
         <div class="date published">${item.publication_date.strftime(str('%-1d %b %Y'))}</div>
-
-        <div py:if="item.tags" class="tags">
-            tagged: ${tag_list('', item.tags)} <!-- XXX script_name -->
-        </div>
-
-        <div class="entry-content">
-            ${item.body}
-        </div>
-
+        <div py:if="item.tags" class="tags">tagged: ${tag_list(item.tags)}</div>
     </div>
-
-    <div>
-        <h2>Previous blog entries</h2>
-        <div class="item blog-entry-stub" py:for="item in sorted_blog_entries[1:4]">
-            <h3 class="entry-title"><a href="blog/${item.id}">${item.title}</a></h3>
-            <div class="date published">${item.publication_date.strftime(str('%-1d %b %Y'))}</div>
-        </div>
-        <a href="blog/">more&#8230;</a>
+    <p><a href="blog/">older entries&#8230;</a></p>
+
+    <h1>Recent reading</h1>
+    <div class="item reading-log-entry-stub" py:for="item in sorted((e for e in reading_entries if e.isbn), key=lambda e: e.publication_date, reverse=True)[:6]">
+        <a py:strip="not item.url" href="${item.url}">
+            <img py:if="item.isbn" class="cover"
+                 src="/covers/isbn/${item.isbn}/thumbnail"
+                 alt="${item.title.striptags()}" />
+        </a>
     </div>
+    <p><a href="reading">older entries&#8230;</a></p>
 
 </body>
 </html>
diff --git a/templates/reading/reading.html b/templates/reading/reading.html
@@ -23,7 +23,7 @@ from viewutils import markdown, mini_markdown, tag_list, idify
         <div class="item reading-log-entry">
 
             <img py:if="item.isbn" class="cover"
-                 src="http://covers.librarything.com/devkey/f6da4b15120267233430bb13cdaf1be9/small/isbn/${item.isbn}" 
+                 src="/covers/isbn/${item.isbn}/thumbnail"
                  alt="Cover image for ${item.title.striptags()}" />
 
             <h3 id="${idify(item.title.striptags())}">
diff --git a/viewutils.py b/viewutils.py
@@ -23,8 +23,7 @@ def idify(s):
 
 ATOM_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S+10:00'
 
-def tag_list(script_name, tags):
-    # XXX urllib.quote
+def tag_list(tags):
     return genshi.Markup(u', ').join(
-            genshi.Markup(u'<a rel="tag" href="%s/tags/%s">%s</a>' % (script_name, tag, tag)) 
+            genshi.Markup(u'<a rel="tag" href="/tags/%s">%s</a>' % (urllib.quote(tag.encode('utf8'), ''), tag)) 
             for tag in tags)