~bzr/bzr-website/trunk

« back to all changes in this revision

Viewing changes to build-site.py

  • Committer: Ian Clatworthy
  • Date: 2010-03-07 15:38:47 UTC
  • mto: This revision was merged to the branch mainline in revision 150.
  • Revision ID: ian.clatworthy@canonical.com-20100307153847-fbyrdiyvww1fkl2k
first cut at template driven home page

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
from jinja2 import Environment, FileSystemLoader
 
4
 
 
5
def save(content, filename):
 
6
    f = open(filename, 'w')
 
7
    try:
 
8
        f.write(content)
 
9
    finally:
 
10
        f.close()
 
11
 
 
12
 
 
13
def get_context():
 
14
    """Return a dictionary of context for rendering templates."""
 
15
    return {
 
16
        'news': get_recent_news(),
 
17
        'blogs': get_recent_blogs(),
 
18
        }
 
19
 
 
20
 
 
21
def get_recent_news():
 
22
    # TODO: get this data from feedburner
 
23
    return [
 
24
        dict(date= "2010-03-05",
 
25
            title="Scmproj 0.5.2 released",
 
26
            url="https://launchpad.net/bzr-scmproj/+announcement/5287"),
 
27
        dict(date= "2010-03-04",
 
28
            title="QBzr 0.18.3 released",
 
29
            url="https://launchpad.net/qbzr/+announcement/5284"),
 
30
        dict(date="2010-02-28",
 
31
            title="Bazaar Explorer 1.0.0 released",
 
32
            url="https://launchpad.net/bzr-explorer/+announcement/5244"),
 
33
        dict(date= "2010-02-26",
 
34
            title="trac-bzr 0.3.2 released",
 
35
            url="https://launchpad.net/trac-bzr/+announcement/5229"),
 
36
        dict(date= "2010-02-24",
 
37
            title="bzr-gtk 0.98.0 released",
 
38
            url="https://launchpad.net/bzr-gtk/+announcement/5219"),
 
39
    ]
 
40
 
 
41
 
 
42
def get_recent_blogs():
 
43
    # TODO: get this data from feedburner
 
44
    return [
 
45
        dict(date= "2010-03-01",
 
46
            title="Bazaar Explorer's Killer Feature",
 
47
            url="http://bazaarvcs.wordpress.com/2010/03/01/bazaar-explorers-killer-feature/"),
 
48
        dict(date= "2010-02-15",
 
49
            title="Bazaar adoption growing strongly",
 
50
            url="http://bazaarvcs.wordpress.com/2010/02/15/bazaar-adoption-growing-strongly/"),
 
51
        dict(date= "2010-02-12",
 
52
            title="gwibber developers on Launchpad and Bazaar",
 
53
            url="http://bazaarvcs.wordpress.com/2010/02/12/gwibber-developers-on-launchpad-and-bazaar/"),
 
54
        dict(date= "2010-01-18",
 
55
            title="Bazaar 2.1, coming through",
 
56
            url="http://bazaarvcs.wordpress.com/2010/01/18/bazaar-2-1-2/"),
 
57
        dict(date= "2010-01-04",
 
58
            title="TortoiseBzr i18n",
 
59
            url="http://bazaarvcs.wordpress.com/2010/01/04/tortoisebzr-i18n/"),
 
60
    ]
 
61
 
 
62
 
 
63
def build(pages):
 
64
    """Build the given pages.
 
65
 
 
66
    :param pages: list of pages to build, e.g. ['index', 'about']
 
67
    """
 
68
    loader = FileSystemLoader("templates")
 
69
    env = Environment(loader=loader)
 
70
    for page in pages:
 
71
        path = "%s.html" % page
 
72
        template = env.get_template(path)
 
73
        context = get_context()
 
74
        result = template.render(context)
 
75
        save(result, "en/%s" % path)
 
76
 
 
77
 
 
78
pages = ['index']
 
79
build(pages)