constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/

tags.py (1119B) - raw

      1 
      2 # vim:fileencoding=utf-8
      3 
      4 import os
      5 import genshi.template
      6 import lxml.etree
      7 
      8 import constance
      9 import viewutils
     10 
     11 template_loader = genshi.template.TemplateLoader(
     12         os.path.join(os.path.realpath(os.path.dirname(__file__)), 'templates', 'tags'), 
     13         variable_lookup='strict')
     14 
     15 def generate(dir, xslt, blog_entries, config):
     16     tag_freqs = {}
     17     for entry in blog_entries:
     18         for tag in entry.tags:
     19             tag_freqs[tag] = tag_freqs.get(tag, 0) + 1
     20 
     21     for tag in tag_freqs.keys():
     22         tagged_entries = [e for e in blog_entries if tag in e.tags]
     23         rendered = template_loader.load('tag.html').generate(tag=tag, items=tagged_entries).render('xhtml', encoding='utf8')
     24         transformed = str(xslt(lxml.etree.fromstring(rendered)))
     25         constance.output(os.path.join(dir, tag.encode('utf8') + '.html'), transformed)
     26 
     27     rendered = template_loader.load('index.html').generate(tag_freqs=tag_freqs,
     28             config=config).render('xhtml', encoding='utf8')
     29     transformed = str(xslt(lxml.etree.fromstring(rendered)))
     30     constance.output(os.path.join(dir, 'index.html'), transformed)