Skip to content

Commit

Permalink
Split template into a base piece shared for more pages, and a main pi…
Browse files Browse the repository at this point in the history
…ece for the frontend.

Add support for building static files if template has changed.

And finally, write a policy document using this method and link it in from the front page.
  • Loading branch information
mhagander committed Oct 25, 2008
1 parent 40194b1 commit fef87f9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
16 changes: 14 additions & 2 deletions generator.py
Expand Up @@ -12,10 +12,12 @@
import PyRSS2Gen
import ConfigParser
import datetime
import os.path
import sys
import tidy
import urllib
from mako.template import Template
from mako.lookup import TemplateLookup
from HTMLParser import HTMLParser
from planethtml import *

Expand All @@ -32,6 +34,7 @@ def __init__(self,db):
)
self.items = []
self.feeds = []
self.staticfiles = ['policy']


def Generate(self):
Expand Down Expand Up @@ -63,13 +66,22 @@ def Generate(self):

rss.write_xml(open("www/rss20.xml","w"), encoding='utf-8')

self.WriteFromTemplate('template/index.tmpl', 'www/index.html')
self.WriteFromTemplate('index.tmpl', 'www/index.html')
for staticfile in self.staticfiles:
self.UpdateStaticFile(staticfile)

def WriteFromTemplate(self, templatename, outputname):
tmpl = Template(filename=templatename, output_encoding='utf-8', input_encoding='utf-8')
lookup = TemplateLookup(directories=['template'], output_encoding='utf-8', input_encoding='utf-8')
tmpl = lookup.get_template(templatename)
f = open(outputname, "w")
f.write(tmpl.render_unicode(feeds=self.feeds, posts=self.items).encode('utf-8'))
f.close()

def UpdateStaticFile(self, filename):
if not os.path.exists("www/%s.html" % (filename)) or \
os.path.getmtime("www/%s.html" % (filename)) < os.path.getmtime("template/%s.tmpl" % (filename)):
print "Updating %s.html" % (filename)
self.WriteFromTemplate("%s.tmpl" % (filename), "www/%s.html" % (filename))


def TruncateAndCleanDescription(self, txt):
Expand Down
23 changes: 23 additions & 0 deletions template/base.tmpl
@@ -0,0 +1,23 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
<head>
<title>Planet PostgreSQL</title>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="Planet PostgreSQL" href="http://planet.postgresql.org/rss20.xml" />
<style type="text/css" media="screen" title="Normal Text">@import url("css/planet.css");</style>
</head>
<body>
<div id="planetWrap">
<div id="planetHeader">
<div class="fl"><img src="http://www.postgresql.org/layout/images/hdr_left.png" alt="PostgreSQL" /></div>
<div class="fr"><img width="210" height="80" src="http://www.postgresql.org/layout/images/hdr_right.png" alt="The world's most advanced open source database" /></div>
<div class="cb"></div>
</div> <!-- planetHeader -->
<div id="planetMain">
${self.body()}
</div> <!-- planetMain -->
</div> <!-- planetWrap -->
</body>
</html>
25 changes: 3 additions & 22 deletions template/index.tmpl
@@ -1,21 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
<head>
<title>Planet PostgreSQL</title>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="Planet PostgreSQL" href="http://planet.postgresql.org/rss20.xml" />
<style type="text/css" media="screen" title="Normal Text">@import url("css/planet.css");</style>
</head>
<body>
<div id="planetWrap">
<div id="planetHeader">
<div class="fl"><img src="http://www.postgresql.org/layout/images/hdr_left.png" alt="PostgreSQL" /></div>
<div class="fr"><img width="210" height="80" src="http://www.postgresql.org/layout/images/hdr_right.png" alt="The world's most advanced open source database" /></div>
<div class="cb"></div>
</div> <!-- planetHeader -->
<div id="planetMain">
<%inherit file="base.tmpl" />
<div id="planetRight">
<div class="planetRightTitle">Subscriptions</div>
<ul>
Expand All @@ -27,6 +10,8 @@
<ul>
<li><a href="rss20.xml"><img src="img/feed-icon-14x14.png" alt="rss" /></a> <a href="rss20.xml">Planet PostgreSQL</a></li>
</ul>
<div class="planetRightTitle">Planet</div>
<p><a href="policy.html">Policy</a> for being listed on Planet PostgreSQL</a></p>
</div> <!-- planetRight -->
<div id="planetLeft">
% for post in posts:
Expand All @@ -42,10 +27,6 @@
</div>
% endfor
</div> <!-- planetLeft -->
</div> <!-- planetMain -->
</div> <!-- planetWrap -->
</body>
</html>
<%def name="coalescelink(txt, link)">
%if link=='':
${txt}
Expand Down
15 changes: 15 additions & 0 deletions template/policy.tmpl
@@ -0,0 +1,15 @@
<%inherit file="base.tmpl" />
<h1>Planet PostgreSQL policy</h1>
<p>
The following simple rules cover the blogs being listed on Planet PostgreSQL:
</p>
<ul>
<li>All blogs should be about PostgreSQL or closely related technologies. If you want to blog
about other things as well, please put your PostgreSQL specific posts in a separate
category/tag/label, and use the feed for this category only for Planet PostgreSQL.</li>
<li>All topics related to PostgreSQL are of course appreciated - both technical and
non-technical.</li>
<li>Avoid inflammatory posts or personal attacks in posts syndicated.</li>
<li>Publishing of advertising in the syndicated part of your blog is not permitted</li>
</ul>
<p>Violating these rules will cause your blog to be removed from Planet PostgreSQL.</p>
4 changes: 4 additions & 0 deletions www/css/planet.css
Expand Up @@ -131,6 +131,10 @@ div#planetRight ul {
padding-left: 15px;
}

div#planetRight p {
padding-left: 15px;
}

div.fl { float: left; border: none; text-align: left; }
div.fr { float: right; }
div.cb { clear: both; }
Expand Down

0 comments on commit fef87f9

Please sign in to comment.