3

自己刻 RSS 2.0 的簡單方式

 1 year ago
source link: https://blog.gslin.org/archives/2022/07/02/10772/%e8%87%aa%e5%b7%b1%e5%88%bb-rss-2-0-%e7%9a%84%e7%b0%a1%e5%96%ae%e6%96%b9%e5%bc%8f/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

自己刻 RSS 2.0 的簡單方式

Lobsters Daily 上看到在介紹 RSS 2.0 的文章:「Implementing RSS for my blog (yes, this one!)」。

大多數我們都會選擇用 library 來輸出 RSS feed 或是 Atom feed,但這並不代表自己己幹 template 會很難,只要處理好 XML 的輸出就可以了。

作者分成兩塊介紹,第一塊是這個 RSS feed 是什麼,第二塊是這個 RSS feed 裡面有什麼。

第一塊的部份是描述 channel 本身的資訊,另外可以看到 {{{items}}} 這段,這是等下要放第二段的部份:

<rss version="2.0">
    <channel">
        <title">title}}</title">
        <link">{{link}}</link">
        <description">{{description}}</description">
        <language">en-US</language">
        <pubDate">pubDate}}</pubDate">
        {{{items}}}
    </channel">
</rss">

接下來就是解釋 items 的部份,裡面可以有很多 item 資料:

<item>
    <title>{{metadata.title}}</title>
    <link>{{getFullUrl slug}}</link>
    <description>{{metadata.summary}}</description>
    <author>[email protected]</author>
    <pubDate>{{rssDatetime metadata.time}}</pubDate>
</item>

你可以靜態寫到檔案裡面,也可以動態產生這個內容,這樣基本上已經會動了。當然,要記得該有的 XML escaping 要放進去。

另外我之前有提到「實做 RSS/Atom feed 的最佳實踐」,也可以參考看看,這算是多做的部份,可以讓 feed crawler 更新速度變得比較即時。

Related

實做 RSS/Atom feed 的最佳實踐

前陣子看到的文章,在講實做 RSS/Atom feed 的 best practice:「RSS Feed Best Practises」。 最簡單的當然還是丟個 Atom feed 就好,接下來就是一些延伸出來可以多做的事情。 首先有提到 discovery,可以讓 crawler 在抓到 HTML 頁面的時候知道 feed 在哪裡,這對於 user experience 來說蠻重要的,大多數的 feed reader 都可以透過這個方式抓到真正的 feed 位置。舉個例子來說,我丟 https://blog.gslin.org/ 進 feed reader,可以透過 discovery 的方式告訴 feed reader 我的 feed 位置在 https://blog.gslin.org/feed/:

May 17, 2022

In "Blog"

用 CSS Selector 產生 RSS feed

在 Hacker News 首頁看到「Show HN: RSS feeds for arbitrary websites using CSS selectors (vincenttunru.com)」這個,程式在 GitLab.com 上的「Feed me up, Scotty!」這邊,另外這個專案名稱是在玩 Star Trek 的梗:「Beam me up, Scotty」,然後這邊講的 RSS feed 已經算是通稱了,實際上大家都是輸出 Atom。 他用的設定檔格式是 TOML,文章給的範例: [funfacts] title = "Wikipedia — did you know?" url = "https://en.wikipedia.org/wiki/Main_Page" entrySelector = "#mp-dyk > ul li" titleSelector =…

July 6, 2021

In "Computer"

無名 Blog 匯出成 MT 格式

給不想看下面說明的人:備份服務的網址是 http://backup.hasname.com/blog/wretch/。 注意:這項服務還有一些小問題,有可能隨時都在改 code。 2006/10/05 20:54 更新:現在的版本會多開幾條連線平行化處理,下載的速度應該會快很多。 2006/10/05 17:30 更新:現在下載的檔名會是 backup-${username}.txt 了,這樣應該比較方便。 雖然在去年六月的時候為了幫 ashley 大姊姊 (a.k.a. 電視兒童) 從 無名 跳出來而用 Perl 寫了一個小程式,將 無名 Blog 上的文章匯出成 RSS 2.0 格式,再匯入 WordPress 裡。後來這個小程式就再加強一下,寫了一個網頁並公開出來 (參考 無名小站的 Blog 與 Album 備份及還原服務 這篇文章),並且希望 無名 提供更完整的匯出及匯入服務。 後來 養樂多 (Yam Roodo) 的 Blog 服務 提供 MT 格式 的匯出與匯入,而國外…

October 4, 2006

In "Blog"

a611ee8db44c8d03a20edf0bf5a71d80?s=49&d=identicon&r=gAuthor Gea-Suan LinPosted on July 2, 2022Categories Computer, Murmuring, Network, Programming, RSS, WWWTags 2.0, atom, feed, rss, xml

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK