Split template into a base piece shared for more pages, and a main piece for the...
authorMagnus Hagander <magnus@hagander.net>
Sat, 25 Oct 2008 21:34:47 +0000 (21:34 +0000)
committerMagnus Hagander <magnus@hagander.net>
Sat, 25 Oct 2008 21:34:47 +0000 (21:34 +0000)
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.

generator.py
template/base.tmpl [new file with mode: 0644]
template/index.tmpl
template/policy.tmpl [new file with mode: 0644]
www/css/planet.css

index e12a6954cf2358c8fd4c43391413a0cbeb8dbcf5..c3229805cf2acdec872943fd26c5ab9498c625e2 100755 (executable)
@@ -12,10 +12,12 @@ import psycopg2.extensions
 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 *
 
@@ -32,6 +34,7 @@ class Generator:
                                        )
                self.items = []
                self.feeds = []
+               self.staticfiles = ['policy']
 
 
        def Generate(self):
@@ -63,13 +66,22 @@ class Generator:
 
                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):
diff --git a/template/base.tmpl b/template/base.tmpl
new file mode 100644 (file)
index 0000000..47283b3
--- /dev/null
@@ -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>
index 0d59c15b7302dc45dec2e65741758a59d4cf804b..d0a72c910820abaea3238e082f96531f292b87f3 100644 (file)
@@ -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>
@@ -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:
      </div>
 % endfor
     </div> <!-- planetLeft -->
-   </div> <!-- planetMain -->
-  </div> <!-- planetWrap -->
- </body>
-</html>
 <%def name="coalescelink(txt, link)">
 %if link=='':
 ${txt}
diff --git a/template/policy.tmpl b/template/policy.tmpl
new file mode 100644 (file)
index 0000000..a399918
--- /dev/null
@@ -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>
index 5a3ae0803a0af9cc7e04a436e4344645d9e6bbc4..bd9daac7734efb8ebd38d1918660368fb85691a5 100644 (file)
@@ -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;  }