更新情報をRSSで提供

各種blogやニュースサイトと同じように、ploneサイトの更新情報をRSSで提供する方法を説明します。

takanori

目次

RSS配信コンテンツを作成[create]

RSSは色々と規格が存在するようで、今回は RSS 1.0RSS 2.0 に対応するようにします。

スキンの作成[skin]

  1. 最初に以下の2つのソースコードをダウンロードします。
  2. 次にzopeの管理画面を開き、portal_skin/custom フォルダにアクセスします。

    Select portal_skin/custom folder

  3. Page Templateアイテムを追加します。

    Add Page Template item

  4. ダウンロードしたファイルを指定して、'Add and Edit'ボタンをクリックしてPage Templateアイテムを作成します。

    Create Page Template item

  5. すると以下のようにエラーメッセージが表示されますが、これは Content-Typetext/xml ではなく text/html となっているためです。 (画像の右上をチェックしてください。)

    TAL error screen

  6. Content-Typetext/xml に変更して保存すると、以下のようにエラーメッセージが表示されなくなります。

    No error screen

  7. 上記の処理を繰り返し index.rdf, index.xml という2つのアイテムを作成します。

    index.rdf and index.xml in custom folder

フォーマットを確認[check]

作成した2つのファイルが配信する内容が、フォーマット的に正しいかを Feed Validator を使用してチェックします。

下記のURLを使ってチェックして、フォーマットに問題がないことを確認しました。

ソースの変更[modify]

配信対象となるのは、最近公開(published)したアイテムを新しい順に15件としています。 件数や対象とするアイテムの種類を限定したい場合は、両方のソースの下記のアイテムを検索する部分を書き換えてください。:

      <tal:search tal:define="results python:here.portal_catalog.searchResults(
        sort_on='modified',
        sort_order='reverse',
        review_state='published')[:15]">

まずは、検索部分について説明します。

headerを変更[header]

次に、RSS情報へのリンクをHTMLのヘッダに入れるために、ploneのヘッダを定義している部分を変更します。

  1. zope管理画面を開き portal_skins/plone_templates にアクセスします。

    Select portal_skin/plone_templates folder

  2. header を選択して Customize ボタンをクリックして、編集用に custom フォルダにコピーします。

    Customize header

  3. コピーした header に以下のようにRSS情報へのリンクを追加します。

    変更前:

        <!-- Basic crude style for Netscape4.x - This can be removed
             if you don't want the special NS4 look - it will still work,
             just be plain text instead. Column layout for Netscape4.x included -->
        <link rel="Stylesheet" type="text/css" href="" tal:attributes="href string:$portal_url/ploneNS4.css" />
    

    変更後:

        <link rel="alternate" type="application/rss+xml" title="RSS 1.0" href=""
              tal:attributes="href string:$portal_url/index.rdf" />
        <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href=""
              tal:attributes="href string:$portal_url/index.xml" />
    
        <!-- Basic crude style for Netscape4.x - This can be removed
             if you don't want the special NS4 look - it will still work,
             just be plain text instead. Column layout for Netscape4.x included -->
        <link rel="Stylesheet" type="text/css" href="" tal:attributes="href string:$portal_url/ploneNS4.css" />
    

  4. 変更後に plone サイトの任意のページを表示し、ヘッダにリンク情報が表示されていることを確認します。 また、 Firefox で表示すると、ライブブックマークに追加するための表示が出るようになります。

    Add live bookmark