constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 497ea5b1d3f845955f7182951cb9211a94f98832
parent f91a913bbc245bbb9a53ad30b41f3f57aa7ffd31
Author: Dan Callaghan <djc@djc.id.au>
Date:   Sat,  7 Jun 2008 17:23:52 +1000

show categories in sidebar; headings for tag and category pages

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

--HG--
extra : convert_revision : 9c8c93e62724b984badf62164ab5c030c6102edd

Diffstat:
Mapp.py | 20++++++++++++++++----
Mblog.py | 9+++++++++
Mtemplates/_commonwrapper.xml | 4+++-
Mtemplates/category.xml | 2++
Mtemplates/tag.xml | 4+++-
5 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/app.py b/app.py
@@ -28,14 +28,20 @@ class BlogApplication(RegexApplication):
 		self.entries = blog.Entries(ENTRIES_DIR)
 
 	def index(self):
-		rendered = template_loader.load('index.xml').generate(entries=self.entries).render('xhtml')
+		rendered = template_loader.load('index.xml').generate(
+				all_categories=self.entries.categories(), 
+				entries=self.entries
+				).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:
 			entry = self.entries[id]
-			rendered = template_loader.load('single.xml').generate(entry=entry).render('xhtml')
+			rendered = template_loader.load('single.xml').generate(
+					all_categories=self.entries.categories(), 
+					entry=entry
+					).render('xhtml')
 			return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
 		except blog.EntryNotFoundError:
 			raise PageNotFound()
@@ -47,7 +53,10 @@ class BlogApplication(RegexApplication):
 			raise PageNotFound()
 		entries = categories[category]
 		rendered = template_loader.load('category.xml').generate(
-				category=category, entries=entries).render('xhtml')
+				all_categories=self.entries.categories(), 
+				category=category, 
+				entries=entries
+				).render('xhtml')
 		return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
 
 	def tag(self, tag):
@@ -57,7 +66,10 @@ class BlogApplication(RegexApplication):
 			raise PageNotFound()
 		entries = by_tag[tag]
 		rendered = template_loader.load('tag.xml').generate(
-				tag=tag, entries=entries).render('xhtml')
+				all_categories=self.entries.categories(), 
+				tag=tag, 
+				entries=entries
+				).render('xhtml')
 		return HttpResponse(rendered, [('Content-Type', 'text/html')], 200)
 
 
diff --git a/blog.py b/blog.py
@@ -48,6 +48,15 @@ class Entries(object):
 				d.setdefault(category, set()).add(entry)
 		return d
 
+	def categories(self):
+		"""
+		Returns a frequency-ordered list of categories.
+		"""
+		by_category = self.by_category()
+		return sorted(by_category.iterkeys(), 
+				key=lambda c: len(by_category[c]), 
+				reverse=True)
+
 	def by_tag(self):
 		d = {}
 		for entry in self:
diff --git a/templates/_commonwrapper.xml b/templates/_commonwrapper.xml
@@ -37,7 +37,9 @@ from app import BASE_URL
 				</li>
 				<li class="categories">
 					<h2>Categories</h2>
-					XXX TODO
+					<ul>
+						<li py:for="category in all_categories" class="cat-item"><a href="${BASE_URL}/+categories/${category}">${category}</a></li>
+					</ul>
 				</li>
 				<li id="archives">
 					<h2>Archives</h2>
diff --git a/templates/category.xml b/templates/category.xml
@@ -11,6 +11,8 @@
 </head>
 <body>
 
+<h2 class="archives">Archive for the ${category} category</h2>
+
 <py:for each="entry in sorted(entries, key=lambda e: e.publication_date, reverse=True)[:20]">
 	${show_entry(entry, show_comments=False)}
 </py:for>
diff --git a/templates/tag.xml b/templates/tag.xml
@@ -7,10 +7,12 @@
 <xi:include href="_entry.xml" />
 
 <head>
-	<title>${tag} tag</title>
+	<title>“${tag}” tag</title>
 </head>
 <body>
 
+<h2 class="archives">Archive for the “${tag}” tag</h2>
+
 <py:for each="entry in sorted(entries, key=lambda e: e.publication_date, reverse=True)[:20]">
 	${show_entry(entry, show_comments=False)}
 </py:for>