constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 4a1ab0c52a078bac5a79dd428fe6567df1b0c49b
parent 10c78d5dc775fb435225453527effcbe992c7c5a
Author: Sam Kingston <sam@sjkwi.com.au>
Date:   Mon, 11 Oct 2010 14:49:01 +1000

don't show blog or reading log sections if they are empty

Diffstat:
Mblog.py | 3+++
Mreading.py | 3+++
Mtemplates/homepage/index.html | 4++++
3 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/blog.py b/blog.py
@@ -66,6 +66,9 @@ class BlogEntrySet(object):
     def __iter__(self):
         return iter(self.entries)
 
+    def __len__(self):
+        return len(self.entries)
+
 def generate(dir, xslt, template_config):
     entries = BlogEntrySet(dir)
     
diff --git a/reading.py b/reading.py
@@ -39,6 +39,9 @@ class ReadingLogEntrySet(object):
     def __iter__(self):
         return iter(self.entries)
 
+    def __len__(self):
+        return len(self.entries)
+
 def generate(filename, xslt, template_config):
     entries = ReadingLogEntrySet(filename)
 
diff --git a/templates/homepage/index.html b/templates/homepage/index.html
@@ -13,6 +13,7 @@ from viewutils import markdown, mini_markdown, tag_list
 
 <body>
 
+    <py:if test="len(blog_entries) != 0">
     <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>
@@ -20,7 +21,9 @@ from viewutils import markdown, mini_markdown, tag_list
         <div py:if="item.tags" class="tags">tagged: ${tag_list(item.tags)}</div>
     </div>
     <p><a href="blog/">older entries&#8230;</a></p>
+    </py:if>
 
+    <py:if test="len(reading_entries) != 0">
     <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}">
@@ -30,6 +33,7 @@ from viewutils import markdown, mini_markdown, tag_list
         </a>
     </div>
     <p><a href="reading">older entries&#8230;</a></p>
+    </py:if>
 
 </body>
 </html>