forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support RSS3 UMS output format (DIYgod#13900)
* feat: support RSS3 UMS output also optimized middleware/template * fix: rss3_ums function name * feat: handle current timestamp in UMS * feat: add authors * chore: update UMS type * chore(deps-dev): bump @types/react from 18.2.37 to 18.2.38 in /website (#2249) Bumps [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) from 18.2.37 to 18.2.38. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react) --- updated-dependencies: - dependency-name: "@types/react" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @types/markdown-it in /website (#2250) Bumps [@types/markdown-it](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/markdown-it) from 13.0.6 to 13.0.7. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/markdown-it) --- updated-dependencies: - dependency-name: "@types/markdown-it" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @types/react-dom in /website (#2252) Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.15 to 18.2.16. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom) --- updated-dependencies: - dependency-name: "@types/react-dom" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @types/react-dom in /website (#2255) Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 18.2.16 to 18.2.17. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom) --- updated-dependencies: - dependency-name: "@types/react-dom" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update lib/middleware/template.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/middleware/template.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/utils/render.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/views/rss3-ums.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/views/rss3-ums.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/utils/render.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * doc: update UMS related docs * Update parameter.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update parameter.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
82cf5c7
commit 3a5488a
Showing
5 changed files
with
147 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
const art = require('art-template'); | ||
const json = require('@/views/json'); | ||
const rss3Ums = require('@/views/rss3-ums'); | ||
|
||
// We may add more control over it later | ||
|
||
module.exports = { | ||
art, | ||
json, // This should be used by RSSHub middleware only. | ||
rss3Ums, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const dayjs = require('dayjs'); | ||
|
||
/** | ||
* This function should be used by RSSHub middleware only. | ||
* @param {object} data ctx.state.data | ||
* @returns `JSON.stringify`-ed [UMS Result](https://docs.rss3.io/docs/unified-metadata-schemas) | ||
*/ | ||
|
||
const NETWORK = 'RSS'; | ||
const TAG = 'RSS'; | ||
const TYPE = 'feed'; | ||
|
||
const rss3Ums = (data) => { | ||
const currentUnixTsp = dayjs().unix(); | ||
const umsResult = { | ||
data: data.item.map((item) => { | ||
const owner = getOwnershipFieldFromURL(item); | ||
return { | ||
owner, | ||
id: item.link, | ||
network: NETWORK, | ||
from: owner, | ||
to: owner, | ||
tag: TAG, | ||
type: TYPE, | ||
direction: 'out', | ||
feeValue: '0', | ||
actions: [ | ||
{ | ||
tag: TAG, | ||
type: TYPE, | ||
platform: owner, | ||
from: owner, | ||
to: owner, | ||
metadata: { | ||
authors: typeof item.author === 'string' ? [{ name: item.author }] : item.author, | ||
description: item.description, | ||
pubDate: item.pubDate, | ||
tags: typeof item.category === 'string' ? [item.category] : item.category, | ||
title: item.title, | ||
}, | ||
related_urls: [item.link], | ||
}, | ||
], | ||
timestamp: dayjs(item.updated).unix() || currentUnixTsp, | ||
}; | ||
}), | ||
}; | ||
return JSON.stringify(umsResult, null, 4); | ||
}; | ||
|
||
// we treat the domain as the owner of the content | ||
function getOwnershipFieldFromURL(item) { | ||
try { | ||
const urlObj = new URL(item.link); | ||
return urlObj.hostname; | ||
} catch (e) { | ||
return item.link; | ||
} | ||
} | ||
|
||
module.exports = rss3Ums; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters