commit 3a08a3e02d1c61c6c5193d0c4aaa542c80b5c2e9
parent 497ea5b1d3f845955f7182951cb9211a94f98832
Author: Dan Callaghan <djc@djc.id.au>
Date: Sat, 7 Jun 2008 18:08:54 +1000
show comment link and count when not showing the full comments
committer: Dan Callaghan <djc@djc.id.au>
--HG--
extra : convert_revision : 5a7844dbc2e03da288dfc62c48db91ca2f8fca23
Diffstat:
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/blog.py b/blog.py
@@ -3,6 +3,12 @@ from datetime import datetime
import markdown
+def count(iterable):
+ count = 0
+ for _ in iterable:
+ count += 1
+ return count
+
def cleanup_metadata(meta):
cleaned = {}
for k, v in meta.iteritems():
@@ -117,6 +123,11 @@ class Comments(object):
def __contains__(self, id):
return os.path.exists(os.path.join(self.path, id))
+
+ def __len__(self):
+ return count(filename
+ for filename in os.listdir(self.path)
+ if not filename.startswith('.'))
def __getitem__(self, id):
return Comment(self.path, id)
diff --git a/templates/_entry.xml b/templates/_entry.xml
@@ -13,6 +13,13 @@
<py:if test="entry.categories">
in <a py:for="category in entry.categories" href="${BASE_URL}/+categories/${category}">${category}</a>
</py:if>
+ <py:if test="not show_comments and entry.has_comments()">
+ ยท
+ <a href="${BASE_URL}/${entry.id}#comments">
+ Comments
+ <py:if test="len(entry.comments()) > 0">(${len(entry.comments())})</py:if>
+ </a>
+ </py:if>
</div>
<div class="entrybody">