John Mulligan avatar John Mulligan committed b3ea223

valid rss and atom feeds

Comments (0)

Files changed (5)

muyhomepage2/app/configuration.py

     def site_atom_id(self):
         return 'tag:asynchrono.us,2006-01-02:birch-street-computing'
 
+    def atom_id_base(self):
+        return 'tag:asynchrono.us'
+

muyhomepage2/pagehandlers/feeds.py

 
 
 class FeedEntryHandler(standard.StandardHandler):
-    pass
-    # linkto
-    # id_tag
+    def __init__(self, config, pg):
+        if not hasattr(pg, 'body'):
+            pg = page.parse(pg.filename)
+        standard.StandardHandler.__init__(self, pg)
+        self.config = config
+
+    def link_ref(self):
+        link = os.path.join(self.config.base_url(), self.finalname())
+        return link
+
+    @property
+    def id_tag(self):
+        return util.atom_id(self.config.atom_id_base(),
+                self.page.created(),
+                self.page.title)
 
 
 class BaseFeedHandler(handler.PageHandler):
         return self.content()
 
     def _getentries(self, website, config):
-        return []
+        wrap = lambda e: FeedEntryHandler(config, e)
+        entries = []
+        for entry in website.newest(config.feed_count()):
+            entries.append(wrap(entry))
+        return entries
 
     def extension(self, website, config):
         site_url = config.base_url()

muyhomepage2/util.py

         return time.strftime(TIME_FMT_MUY, self.utc())
 
     def dayfmt(self):
-        return time.strftime(TIME_FMT_ATOMID, self.local())
+        return time.strftime(TIME_FMT_ATOMID, self.utc())
+
+    def atomfmt(self):
+        return time.strftime(TIME_FMT_3339, self.utc())
+
+    def rfc822fmt(self):
+        return time.strftime(TIME_FMT_822, self.local())
 
     @classmethod
     def parse(cls, txt):
     def now(cls):
         return cls(time.time())
 
+def atom_id(base, when, title):
+    return '%s,%s:%s' % (base, when.dayfmt(), encodetitle(title))

skins/default/atom.xml

 <?xml version="1.0" encoding="utf-8" ?>
 <feed xmlns="http://www.w3.org/2005/Atom">
+
     <title>{{current.page.title}}</title>
     <link href="{{ext.site_url}}"></link>
     <link rel="self" href="{{ext.self_url}}"></link>
-    <updated>{{ext.feed_updated}}</updated>
+    <updated>{{ext.feed_updated.atomfmt()}}</updated>
 
     <author>
         <name>{{ext.feed_author}}</name>
     {% for entry in ext.entries %}
     <entry>
         <title>{{entry.page.title}}</title>
-        <link href="{{entry.linkto}}"></link>
-        <updated>{{entry.modifiedon.atomfmt}}</updated>
-        <published>{{entry.createdon.atomfmt}}</published>
+        <link href="{{entry.link_ref()}}"></link>
+        <updated>{{entry.modifiedon.atomfmt()}}</updated>
+        <published>{{entry.createdon.atomfmt()}}</published>
 
-        <content type="html">
-            {{entry.content()|e}}
-        </content>
+      <content type="html">
+      {{entry.content()|e}}
+      </content>
 
         <id>{{entry.id_tag}}</id>
     </entry>

skins/default/rss2.xml

 <?xml version="1.0"?>
 <rss version="2.0">
-<channel>
+  <channel>
 
-  <title>{{current.page.title}}</title>
-  <link>{{ext.site_url}}</link>
-  <description>{{current.description}}</description>
+    <title>{{current.page.title}}</title>
+    <link>{{ext.site_url}}</link>
+    <language>en-us</language>
+    <description>{{current.description|e}}</description>
 
-  {% for entry in ext.entries %}
-  <item> 
-    <title>{{entry.page.title}}</title>
-    <link>{{entry.linkto}}</link>
-    <pubDate>{{entry.createdon.rfc822fmt}}</pubDate>
+    {% for entry in ext.entries %}
+    <item> 
+      <title>{{entry.page.title}}</title>
+      <link>{{entry.link_ref()}}</link>
+      <pubDate>{{entry.createdon.rfc822fmt()}}</pubDate>
+  
+      <description>
+        {{entry.content()|e}}
+      </description>
     
-    <description>
-     {{entry.content|e}}
-    </description>
-    
-    <guid>{{entry.linkto}}</guid>
-  </item>
-  {% endfor %}
+      <guid>{{entry.link_ref()}}</guid>
+    </item>
+    {% endfor %}
 
-</channel>
+  </channel>
 </rss>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.