From 6b7381e1e3c41c395ee1dabbd004901765ada25f Mon Sep 17 00:00:00 2001 From: Bin Wang Date: Sun, 17 Apr 2022 14:54:32 -0400 Subject: [PATCH] feat(core): add custom fields to atom feed (#9355) * Add custom fields to atom feed Atom allows to extend the xml with custom namespaces. This commit is a first commit that tries to add some custom RSSHub fields to atom feed. In this commit, I added three very common fields: upvotes, downvotes and comments. Lots of websites has these common fields, like Youtube, Twitter, Reddit, HackerNews and so on. Within these fields, RSS readers can have more information to sort the contents, and can display these information to user in a better format. The document has been updated to reflect these new fields. I also changed Bilibili video route as an example to show how to add number of comments to the generated feed. * docs: interactions --- docs/en/joinus/quick-start.md | 18 +++++++++++++++++- docs/joinus/quick-start.md | 16 ++++++++++++++++ lib/v2/bilibili/video.js | 1 + lib/views/atom.art | 14 +++++++++++++- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/docs/en/joinus/quick-start.md b/docs/en/joinus/quick-start.md index 07db6bcad..24a58304c 100644 --- a/docs/en/joinus/quick-start.md +++ b/docs/en/joinus/quick-start.md @@ -371,7 +371,7 @@ ctx.state.data = { ##### Media RSS -these **additional** data are in accordance with many [Media RSS](http://www.rssboard.org/media-rss) softwares' subscription format: +These **additional** data are in accordance with many [Media RSS](http://www.rssboard.org/media-rss) softwares' subscription format: For example: @@ -393,6 +393,22 @@ ctx.state.data = { }; ``` +##### Interactions + +These **additional** data are in accordance with some softwares' subscription format: + +```js +ctx.state.data = { + item: [ + { + upvotes: 0, // default to undefined, how many upvotes for this article, + downvotes: 0, // default to undefined, how many downvotes for this article, + comments: 0, // default to undefined, how many comments for this article + }, + ], +}; +``` + --- ### Add the documentation diff --git a/docs/joinus/quick-start.md b/docs/joinus/quick-start.md index 26c980c3c..abe676ad8 100644 --- a/docs/joinus/quick-start.md +++ b/docs/joinus/quick-start.md @@ -394,6 +394,22 @@ ctx.state.data = { }; ``` +##### 互动 + +**额外**添加这些字段能使你的 RSS 被支持的软件订阅: + +```js +ctx.state.data = { + item: [ + { + upvotes: 0, // 默认为空,文章有多少 upvote + downvotes: 0, // 默认为空,文章有多少 downvote + comments: 0, // 默认为空,文章有多少评论 + }, + ], +}; +``` + * * * ### 添加脚本文档 diff --git a/lib/v2/bilibili/video.js b/lib/v2/bilibili/video.js index 0f728233c..ec0b77117 100644 --- a/lib/v2/bilibili/video.js +++ b/lib/v2/bilibili/video.js @@ -32,6 +32,7 @@ module.exports = async (ctx) => { pubDate: new Date(item.created * 1000).toUTCString(), link: item.created > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.aid}`, author: name, + comments: item.comment, })), }; }; diff --git a/lib/views/atom.art b/lib/views/atom.art index b0a754795..e023ff16c 100644 --- a/lib/views/atom.art +++ b/lib/views/atom.art @@ -1,5 +1,5 @@ - + RSSHub i@diygod.me (DIYgod) {{ language || 'zh-cn' }} @@ -50,6 +50,18 @@ + {{ if $e.upvotes }} + {{ $e.upvotes }} + {{ /if }} + + {{ if $e.downvotes }} + {{ $e.downvotes }} + {{ /if }} + + {{ if $e.comments }} + {{ $e.comments }} + {{ /if }} + {{ if $e.summary }} {{ /if }}