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
This commit is contained in:
parent
455594aff2
commit
6b7381e1e3
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -394,6 +394,22 @@ ctx.state.data = {
|
|||
};
|
||||
```
|
||||
|
||||
##### 互动
|
||||
|
||||
**额外**添加这些字段能使你的 RSS 被支持的软件订阅:
|
||||
|
||||
```js
|
||||
ctx.state.data = {
|
||||
item: [
|
||||
{
|
||||
upvotes: 0, // 默认为空,文章有多少 upvote
|
||||
downvotes: 0, // 默认为空,文章有多少 downvote
|
||||
comments: 0, // 默认为空,文章有多少评论
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
### 添加脚本文档
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:rsshub="http://rsshub.app/xml/schemas">
|
||||
<generator>RSSHub</generator>
|
||||
<webMaster>i@diygod.me (DIYgod)</webMaster>
|
||||
<language>{{ language || 'zh-cn' }}</language>
|
||||
|
|
@ -50,6 +50,18 @@
|
|||
|
||||
<link href="{{ $e.link }}" />
|
||||
|
||||
{{ if $e.upvotes }}
|
||||
<rsshub:upvotes>{{ $e.upvotes }}</rsshub:upvotes>
|
||||
{{ /if }}
|
||||
|
||||
{{ if $e.downvotes }}
|
||||
<rsshub:downvotes>{{ $e.downvotes }}</rsshub:downvotes>
|
||||
{{ /if }}
|
||||
|
||||
{{ if $e.comments }}
|
||||
<rsshub:comments>{{ $e.comments }}</rsshub:comments>
|
||||
{{ /if }}
|
||||
|
||||
{{ if $e.summary }}
|
||||
<summary type="html"><![CDATA[{{@ $e.summary }}]]></summary>
|
||||
{{ /if }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue