constance

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

do mini_markdown in the template

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

--HG--
extra : convert_revision : fd757bb5cf0c0c851fe0ad24d6058202042d90a6

Diffstat:
Mblog.py | 10++--------
Mtemplates/_entry.xml | 8++++++--
Aviewutils.py | 10++++++++++
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/blog.py b/blog.py
@@ -21,12 +21,6 @@ def cleanup_metadata(meta):
 		cleaned[k] = v
 	return cleaned
 
-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)
-
 
 class EntryNotFoundError(ValueError): pass
 
@@ -103,7 +97,7 @@ class Entry(object):
 		md = markdown.Markdown(extensions=['meta', 'typography'])
 		self.body = genshi.Markup(md.convert(self.raw))
 		self.metadata = cleanup_metadata(md.Meta)
-		self.title = mini_markdown(self.metadata['title'])
+		self.title = self.metadata['title']
 
 		raw_cats = self.metadata.get('categories', '').strip()
 		if raw_cats:
@@ -134,7 +128,7 @@ class Entry(object):
 class ReadingLogEntry(object):
 
 	def __init__(self, yaml_dict):
-		self.title = mini_markdown(yaml_dict['Title'])
+		self.title = yaml_dict['Title']
 		self.author = yaml_dict['Author']
 		self.publication_date = self.modified_date = self.date = yaml_dict['Date']
 		self.url = yaml_dict.get('URL', None)
diff --git a/templates/_entry.xml b/templates/_entry.xml
@@ -4,9 +4,13 @@
 	 py:strip="True"
 	 py:def="show_entry(entry, show_comments=True)">
 
+<?python
+from viewutils import mini_markdown
+?>
+
 <div class="entry" py:if="'Reading' not in entry.categories">
 
-	<h3 class="entrytitle" id="post-${entry.id}"><a href="${BASE_URL}/${entry.id}" rel="bookmark">${entry.title}</a></h3>
+	<h3 class="entrytitle" id="post-${entry.id}"><a href="${BASE_URL}/${entry.id}" rel="bookmark">${mini_markdown(entry.title)}</a></h3>
 
 	<div class="entrymeta">
 		Posted ${entry.publication_date.strftime(str('%-1d %B %Y'))}
@@ -39,7 +43,7 @@
 
 <div class="entry readinglog" py:if="'Reading' in entry.categories">
 	<h3 class="entrytitle">
-		<a py:strip="not entry.url" href="${entry.url}">${entry.title}</a>
+		<a py:strip="not entry.url" href="${entry.url}">${mini_markdown(entry.title)}</a>
 		<py:if test="entry.author">
 			by ${entry.author}
 		</py:if>
diff --git a/viewutils.py b/viewutils.py
@@ -0,0 +1,10 @@
+import re
+import markdown
+import genshi
+
+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)
+