Commits

John Mulligan committed 6e64ad1

blog page support

Comments (0)

Files changed (5)

muyhomepage2/app/configuration.py

 from muyhomepage2.pagehandlers.tagsummary import TagSummaryHandler
 from muyhomepage2.pagehandlers.tagglobal import TagGlobalHandler
 from muyhomepage2.pagehandlers.software import SoftwareHandler
+from muyhomepage2.pagehandlers.blog import BlogHandler
 
 
 DEFAULT_HANDLERS = {
     'standard': StandardHandler,
-    'blog': StandardHandler,
+    'blog': BlogHandler,
     'tagsummary': TagSummaryHandler,
     'tagglobal': TagGlobalHandler,
     'software': SoftwareHandler,
     def always_rebuild(self):
         return ['tagsummary', 'tagglobal', 'atom', 'rss2', 'blog']
 
+    def blog_count(self):
+        return 10
+
+    def feed_count(self):
+        return 20
+

muyhomepage2/pagehandlers/blog.py

+
+from muyhomepage2.pagehandlers import handler
+from muyhomepage2.pagehandlers import standard
+from muyhomepage2.text import wikirst
+from muyhomepage2 import page
+from muyhomepage2 import util
+
+
+class BlogHandler(handler.PageHandler):
+    def content(self):
+        return wikirst.format(self.page.body)
+
+    def template(self):
+        return 'blog.html'
+
+    def extension(self, website, config):
+        def wrap(pg):
+            if not hasattr(pg, 'body'):
+                pg = page.parse(pg.filename)
+            return standard.StandardHandler(pg)
+        entries, days = [], []
+        for entry in website.newest(config.blog_count()):
+            day = entry.created().dayfmt()
+            if day not in days:
+                days.append(day)
+            else:
+                day = None
+            entries.append((day, wrap(entry)))
+    
+        return {
+            'entries': entries,
+            }

muyhomepage2/site.py

 
 import os
+import heapq
 from muyhomepage2 import util
 from muyhomepage2 import page
 from muyhomepage2 import metadata
                 return './%s.html' % util.encodetitle(page.title)
         return None
 
+    def newest(self, num):
+        return heapq.nlargest(num, self.pages,
+            key=lambda p : p.created())
+
 
 
 def write_site_pages(wsite, filename):

muyhomepage2/util.py

     def utc(self):
         return time.gmtime(self._time)
 
+    def __cmp__(self, other):
+        return cmp(self._time, other._time)
+
     def __int__(self):
         return int(self._time)
 
     def storefmt(self):
         return time.strftime(TIME_FMT_MUY, self.utc())
 
+    def dayfmt(self):
+        return time.strftime(TIME_FMT_ATOMID, self.local())
+
     @classmethod
     def parse(cls, txt):
         utc = True

skins/default/blog.html

+{% extends "base.html" %}
+{% import "components.html" as components %}
+
+{% block main %}
+<div id="page-content">
+  <h2>{{current.page.title}}</h2>
+  <div class="intro-text">
+    {{current.content()}}
+  </div>
+
+{% for dateline, entry in ext.entries %}
+  <div class="blog-listing">
+    {% if dateline %}
+    <h4 class="dateline">{{dateline}}</h4>
+    {% endif %}
+    <div>
+      <h2>{{entry.page.title}}</h2>
+      {{ components.tagicon(entry, config) }}
+      <div></div>
+      <div class="written-text">
+        {{entry.content()}}
+      </div>
+      <div></div>
+      {{ components.tidbits(entry, site) }}
+    </div>
+  </div>
+{% endfor %}
+</div>
+{% endblock %}