constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit e6dc33b4701f4d8d5e19bf3e8c4b42da2a7f6be1
parent 589fde17c9c79bcd6e1e60f9c8c260751573ffd2
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sun,  8 Jun 2008 01:10:54 +1000

proper comma-separated lists for categories and tags

committer: Dan Callaghan <djc@djc.id.au>

--HG--
extra : convert_revision : be9f0ece3d64b81e9db9f513e91e617c6ffd7e09

Diffstat:
Mtemplates/_entry.xml | 6+++---
Mviewutils.py | 11+++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/templates/_entry.xml b/templates/_entry.xml
@@ -5,7 +5,7 @@
 	 py:def="show_entry(entry, show_comments=True)">
 
 <?python
-from viewutils import mini_markdown
+from viewutils import mini_markdown, tag_list, category_list
 ?>
 
 <div class="entry" py:if="'Reading' not in entry.categories">
@@ -15,7 +15,7 @@ from viewutils import mini_markdown
 	<div class="entrymeta">
 		Posted ${entry.publication_date.strftime(str('%-1d %B %Y'))}
 		<py:if test="entry.categories">
-			in <a py:for="category in entry.categories" href="${BASE_URL}/+categories/${category}">${category}</a>
+			in ${category_list(entry.categories)}
 		</py:if>
 		<py:if test="not show_comments and entry.has_comments()">
 			ยท
@@ -30,7 +30,7 @@ from viewutils import mini_markdown
 		${entry.body}
 		<p py:if="entry.tags">
 			<img src="${BASE_URL}/static/images/tag_blue.png" alt="Tags:" />
-			<a py:for="tag in entry.tags" rel="tag" href="${BASE_URL}/+tags/${tag}">${tag}</a>
+			${tag_list(entry.tags)}
 		</p>
 	</div>
 
diff --git a/viewutils.py b/viewutils.py
@@ -2,9 +2,20 @@ import re
 import markdown
 import genshi
 
+from app import BASE_URL
+
 def mini_markdown(s):
 	# XXX find a more efficient way to do this?
 	m = markdown.Markdown(extensions=['typography']).convert(s)
 	the_p, = re.match(u'<p>(.*)\n</p>', m).groups()	
 	return genshi.Markup(the_p)
 
+def category_list(categories):
+	return genshi.Markup(u', ').join(
+			genshi.Markup(u'<a href="%s/+categories/%s">%s</a>' % (BASE_URL, category, category)) 
+			for category in categories)
+
+def tag_list(tags):
+	return genshi.Markup(u', ').join(
+			genshi.Markup(u'<a rel="tag" href="%s/+tags/%s">%s</a>' % (BASE_URL, tag, tag)) 
+			for tag in tags)