M muyhomepage2/app/configuration.py +8 -1
@@ 3,11 3,12 @@ from muyhomepage2.pagehandlers.standard
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,
@@ 44,3 45,9 @@ class Config(object):
def always_rebuild(self):
return ['tagsummary', 'tagglobal', 'atom', 'rss2', 'blog']
+ def blog_count(self):
+ return 10
+
+ def feed_count(self):
+ return 20
+
A => muyhomepage2/pagehandlers/blog.py +32 -0
@@ 0,0 1,32 @@
+
+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,
+ }
M muyhomepage2/site.py +5 -0
@@ 1,5 1,6 @@
import os
+import heapq
from muyhomepage2 import util
from muyhomepage2 import page
from muyhomepage2 import metadata
@@ 29,6 30,10 @@ class Site(object):
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):
M muyhomepage2/util.py +6 -0
@@ 64,6 64,9 @@ class When(object):
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)
@@ 73,6 76,9 @@ class When(object):
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
A => skins/default/blog.html +29 -0
@@ 0,0 1,29 @@
+{% 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 %}