Permalink
Browse files

quick and dirty rss support

  • Loading branch information...
1 parent 3d8743f commit 8122bcf766243879740b0ab860fb8758c1cd5299 @twopoint718 committed Aug 4, 2011
Showing with 62 additions and 0 deletions.
  1. +1 −0 Makefile
  2. +59 −0 build_rss.py
  3. +2 −0 layout.html.st
View
@@ -2,6 +2,7 @@ all:
yst
publish: all
+ python build_rss.py > site/blog.rss
rsync -avz site/* chris@wolffia:/var/www/
clean:
View
@@ -0,0 +1,59 @@
+import yaml
+import uuid
+import time
+import sys
+
+yaml_file = "posts.yaml"
+date_fmt= "%a, %d %b %Y 00:00:00 +0000"
+datetime_fmt = "%a, %d %b %Y %H:%M:%S +0000"
+ymd_fmt= "%Y-%m-%d"
+item_template = """<item>
+ <title><![CDATA[%(title)s]]></title>
+ <description><![CDATA[%(postbody)s]]></description>
+ <link>blog.html#%(ymd_date)s</link>
+ <guid>%(guid)s</guid>
+ <pubDate>%(date_fmt)s</pubDate>
+</item>
+"""
+
+header_template = """<?xml version="1.0" encoding="UTF-8" ?>
+<rss version="2.0">
+<channel>
+<title>sencjw.com - rss feed</title>
+<description>recent blog posts from sencjw.com</description>
+<link>http://sencjw.com/blog.html</link>
+<lastBuildDate>%(build_date)s</lastBuildDate>
+<pubDate>%(pub_date)s</pubDate>
+"""
+
+foot_template = """</channel>
+</rss>
+"""
+
+def build_items(outfile):
+ with open(yaml_file, "r") as f:
+ posts = yaml.load(f.read())
+ for post in posts:
+ date = post['date']
+ post['guid'] = str(uuid.uuid1())
+ post['ymd_date'] = date.strftime(ymd_fmt)
+ post['date_fmt'] = date.strftime(date_fmt)
+ out = item_template % post
+ outfile.write(out.encode("utf-8"))
+
+def build_header(outfile):
+ info = dict()
+ curr_time = time.strftime(datetime_fmt)
+ info['build_date'] = curr_time
+ info['pub_date'] = curr_time
+ out = header_template % info
+ outfile.write(out.encode("utf-8"))
+
+def main():
+ f = sys.stdout
+ build_header(f)
+ build_items(f)
+ f.write(foot_template)
+
+if __name__ == "__main__":
+ main()
View
@@ -5,6 +5,8 @@
<link rel="stylesheet" type="text/css" href="$root$css/screen.css" />
<link rel="stylesheet" type="text/css" media="print"
href="$root$css/print.css" />
+ <link rel="alternate" type="application/rss+xml" title="RSS Feed"
+ href="blog.rss" />
<script src="$root$js/jquery.min.js"
type="text/javascript"></script>
<script src="$root$js/nav.js" type="text/javascript"></script>

0 comments on commit 8122bcf

Please sign in to comment.