mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-16 07:44:44 +08:00
* 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>
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
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;
|