takanory.netの「更新情報をRSSで提供」のページを参考にして
RSS 1.0、RSS 2.0の記事全文付きfeedやってみました。
(向こうの記事を読んでからこの記事を読むとわかりやすいでしょう)
参考ページ. takanory.net「更新情報をRSSで提供」
http://takanory.net/plone/custom/updaterss
ただし、環境はかなり古いのです。
Ploneは今では3.0までバージョン上がってしまっているらしいけど、
手元の環境は以下の通りです。
Plone 2.1.3, Zope (Zope 2.7.8-final, python 2.3.5, darwin), Python 2.3.5 (#1, Jan 18 2006, 11:45:33) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)], PIL 1.1.5
作ったテンプレートはこんなものです。
rss10.rdf.txt
RSS 1.0用 (rss10.rdf) <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns="http://purl.org/rss/1.0/" xmlns:tal="http://xml.zope.org/namespaces/tal"> <tal:dummy tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/xml;; charset=utf-8')" /> <tal:search> <tal:dummy tal:define="global items python:context.portal_catalog.searchResults( sort_on='modified', sort_order='reverse', review_state=['published','visible'], path='/Plone/articles', portal_type=['Document'])[:15]" /> </tal:search> <channel tal:attributes="rdf:about here/portal_url"> <title tal:content="context/title">Title of site</title> <link tal:content="context/absolute_url">http://plone.org</link> <description>「名無しのvim使い」へようこそ。このサイトはUnix系エディタviの後継、vimエディタの基本の基本から、スクリプトでの機能拡張までを扱うvimエディタ専門の情報サイトです。</description> <dc:publisher>mail@nanasi.jp (小見 拓)</dc:publisher> <dc:creator>mail@nanasi.jp (小見 拓)</dc:creator> <image tal:attributes="rdf:resource string:${context/portal_url}/${context/base_properties/logoName}"/> <dc:language tal:content="context/portal_properties/site_properties/default_language">en</dc:language> <admin:errorReportsTo rdf:resource="mailto:mail@nanasi.jp" /> <admin:generatorAgent rdf:resource="http://nanasi.jp/" /> <items> <rdf:Seq> <tal:block tal:repeat="item items"> <rdf:li tal:attributes="rdf:resource item/getURL | item/absolute_url" /> </tal:block> </rdf:Seq> </items> </channel> <image tal:attributes="rdf:about string:${context/portal_url}/${context/base_properties/logoName}"> <url tal:content="string:${context/portal_url}/${context/base_properties/logoName}"> http://plone.org/logo.jpg </url> <title tal:content="context/title">Title of site</title> <link tal:content="context/absolute_url">http://plone.org</link> </image> <item tal:repeat="item items" tal:attributes="rdf:about item/getURL | item/absolute_url"> <title tal:content="item/Title">Title of item</title> <link tal:content="item/getURL | item/absolute_url">http://plone.org/itemurl</link> <description tal:content="item/Description">description</description> <dc:subject>名無しのvim使い 記事一覧</dc:subject> <dc:creator>mail@nanasi.jp (小見 拓)</dc:creator> <dc:date tal:define="date item/modified" tal:content="date/ISO8601">2005-02-16T12:00:00+09:00</dc:date> <content:encoded tal:define="item_object item/getObject"><span tal:replace="item_object/CookedBody" /></content:encoded> </item> </rdf:RDF>rss20.xml.txt
RSS 2.0用 (rss20.xml) <?xml version="1.0"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:tal="http://xml.zope.org/namespaces/tal" > <tal:dummy tal:define="dummy python:request.RESPONSE.setHeader('Content-Type', 'text/xml;; charset=utf-8')" /> <channel> <title tal:content="context/title">Title of site</title> <link tal:content="context/absolute_url">http://plone.org</link> <description>「名無しのvim使い」へようこそ。このサイトはUnix系エディタviの後継、vimエディタの基本の基本から、スクリプトでの機能拡張までを扱うvimエディタ専門の情報サイトです。</description> <language tal:content="context/portal_properties/site_properties/default_language">en</language> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <generator>名無しのvim使い</generator> <managingEditor>mail@nanasi.jp (小見 拓)</managingEditor> <webMaster>mail@nanasi.jp</webMaster> <image> <url tal:content="string:${context/portal_url}/${context/base_properties/logoName}"> http://plone.org/logo.jpg </url> <title tal:content="context/title">Title of site</title> <link tal:content="context/absolute_url">http://plone.org</link> <description>名無しのvim使い</description> </image> <tal:search> <tal:dummy tal:define="global items python:context.portal_catalog.searchResults( sort_on='modified', sort_order='reverse', review_state=['published','visible'], path='/Plone/articles', portal_type=['Document'])[:15]" /> </tal:search> <item tal:repeat="item items"> <guid isPermaLink="true" tal:content="item/getURL | item/absolute_url">http://plone.org/itemurl</guid> <title tal:content="item/Title">Title of item</title> <link tal:content="item/getURL | item/absolute_url">http://plone.org/itemurl</link> <description tal:content="item/Description">description</description> <author>mail@nanasi.jp (小見 拓)</author> <category>名無しのvim使い 記事一覧</category> <pubDate tal:define="date item/modified" tal:content="date/rfc822">Wed, 16 Feb 2005 12:00:00 +0900</pubDate> <content:encoded tal:define="item_object item/getObject"><span tal:replace="item_object/CookedBody" /></content:encoded> </item> </channel> </rss>
これらのテンプレートをPageTemplateとして、
Ploneの「portal_skins/custom」ディレクトリに登録すると、
- ${PloneのURL}/rss10.rdf とか、
- ${PloneのURL}/rss20.xml
動的なPloneのサイトで、この方法を使用すると
- ${PloneのURL}/news/rss20.xml
- ${PloneのURL}/events/category/rss20.xml
それが困るという人は自分で解決してください。
このテンプレートは思いっきり「名無しのvim使い」用の設定になっているから、
そのまま使うのはかなり問題があります。
凡庸的に使えるようにもなっていません。いろいろやらねばならないことがあるのです。
記事のカテゴリを動的に変えるとか、記事のguidを変えるとか、
記事の検索パスを違うものにするとか、などのカスタマイズも自分でしてください。
私は面倒だから直接設定を書いてしまいまっています。
動的Ploneサイトを公開している場合には、RSS出力のMIMEタイプにも注意が必要です。
(これはほぼ全てのPloneサイトが該当します)
RSS 1.0では、
- application/rss+xml
- application/rdf+xml
- application/xml
- application/rss+xml
- application/xml
「名無しのvim使い」ではPloneの静的コンテンツ出力をしているから .htaccessでコントロールできるけれど、
普通のPloneサイトでは対応が必要なのではないですかね?
(そのままでもRSSリーダーで読めることは多いみたいなので気にしなくてもいいかも。)
で、最後に気づいたことがあるのです。
RSSに「content:encoded」で記事の本文を入れる場合、
画像のパスはホスト名を含むURLにしなければ表示できません。
(そう思っていました。)
- × /dist/img/logo.jpg
- ○ http://nanasi.jp/dist/img/logo.jpg
しかし、Google Readerと、WebブラウザSafariの組み込みRSSリーダーでは、
画像PATHがホスト名を含むURLでなく、
/(スラッシュ)から始まる部分的なURLでも、きっちりと画像を表示してくれるのです。
相対URLの場合はトップディレクトリ以外にある記事だと駄目みたいですけど、
それでも、なかなかがんばって解釈してくれています。
完璧なRSSを出力している方や、リンク情報を含まないRSS feedを出力している方は、
この親切(?)な仕様には、なかなか気づかないのではないかな?
(Bloglinesもこの仕様を採用するといいのに)
今日は以上。では。