homepage.py (1015B) - raw
1 2 # vim:fileencoding=utf-8 3 4 import os 5 from itertools import chain 6 import genshi.template 7 import lxml.etree 8 9 import constance 10 import viewutils 11 12 template_loader = genshi.template.TemplateLoader( 13 os.path.join(os.path.realpath(os.path.dirname(__file__)), 'templates', 'homepage'), 14 variable_lookup='strict') 15 16 def generate(dir, xslt, blog_entries, reading_entries, config): 17 # index 18 template = template_loader.load('index.html') 19 rendered = template.generate(blog_entries=blog_entries, 20 reading_entries=reading_entries, 21 config=config).render('xhtml', encoding='utf8') 22 transformed = str(xslt(lxml.etree.fromstring(rendered), homepage='1')) 23 constance.output(os.path.join(dir, 'index.html'), transformed) 24 25 # firehose 26 rendered = template_loader.load('firehose.atom').generate( 27 items=chain(blog_entries, reading_entries), 28 config=config).render('xml', encoding='utf8') 29 constance.output(os.path.join(dir, 'firehose.atom'), rendered)