完成ATOM的feed输出

Friday, May 08 14:26, 2009
0 comments/436 hits

我记得原来订阅的RSS,怎么现在都交ATOM了呢?到网上查了一下,才发现ATOM是RSS的升级版。。。比RSS简单,而且可以同时支持摘要和全文,虽然我只想要全文。

要支持ATOM的Feed也很简单,首先在首页的head里面加上如下的语句,这样可以让Firefox等浏览器检测到该页含有Feed链接,从而在地址栏或者其他的地方出现一个Feed标志的小图标:

<link rel="alternate" type="application/atom+xml" title="BlowBlood" href="http://www.blowblood.com/atom">

然后制作/atom页面即可。首先在main.py里面添加url的控制语句,使得/atom页面被blog类的相应方法:FeedHandler所控制,然后在FeedHandler方法中构建atom页面需要的内容,主要是每个post的内容,和该次更新的时间,时间可以取最新一篇post的时间(如果没有的话,则取当前时间),然后把这些数据输出到文件atom.xml中即可。atom.xml的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title><![CDATA[BlowBlood]]></title>
    <id>http://www.blowblood.com-by-gzguoer</id>
    <subtitle>BlowBlood@WestGate</subtitle>
    <link href="http://www.blowblood.com" />
    <link href="http://www.blowblood.com/atom" rel="self" />
    <updated>{{last_updated}}</updated>
    <author>
      <name>blowblood</name>
    </author>
    {%for post in posts%}
  <entry>
      <link href="{{post.full_permalink}}"/>
      <id>{{post.full_permalink}}</id>
      <title><![CDATA[ {{post.title}} ]]></title>
      <content type="html"><![CDATA[ {{post.content}} ]]></content>
      <author>
          <name>{{post.author}}</name>
      </author>
      <updated>{{post.formatted_date}}</updated>
  </entry>
     {%endfor%}
</feed>

然后就行了,哈哈,是不是非常简单呢?

不过有个很普遍的问题,msIE6出生的时候,还没有RSS这玩意,或者没有引起关注,总之IE6还不支持atom,应该有办法可以解决。。

恩,这个编辑器真的不太好用,非常郁闷,在Code和View之间切换的时候,<br />会变成<br>,而且光标所在也不对。。。难道逼我改进吗?或者我直接换一个nb的richtexteditor?

Author: gzguoer Categories: mindcyclone Tags: BBBlogATOM