mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-17 05:11:57 +08:00
08a38f0a5e
* refactor: typing house-keeping * fix: fix parse date not accepting strict mode * refactor: use npm package * fix: address review
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import dayjs from 'dayjs';
|
|
|
|
import type { DataItem } from '@/types';
|
|
|
|
/**
|
|
* 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 = 'rsshub';
|
|
const TAG = 'RSS';
|
|
const TYPE = 'feed';
|
|
const PLATFORM = 'RSSHub';
|
|
|
|
const rss3 = (data) => {
|
|
const currentUnixTsp = dayjs().unix();
|
|
const umsResult = {
|
|
data: data.item.map((item: DataItem) => {
|
|
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: PLATFORM,
|
|
from: owner,
|
|
to: owner,
|
|
metadata: {
|
|
authors: item.author === undefined || Array.isArray(item.author) ? item.author : [{ name: item.author }],
|
|
description: item.description,
|
|
pub_date: item.pubDate,
|
|
tags: item.category === undefined || Array.isArray(item.category) ? item.category : [item.category],
|
|
title: item.title,
|
|
},
|
|
related_urls: [item.link],
|
|
},
|
|
],
|
|
timestamp: dayjs(item.updated).unix() || currentUnixTsp,
|
|
};
|
|
}),
|
|
};
|
|
return umsResult;
|
|
};
|
|
|
|
// we treat the domain as the owner of the content
|
|
function getOwnershipFieldFromURL(item) {
|
|
try {
|
|
const urlObj = new URL(item.link);
|
|
return urlObj.hostname;
|
|
} catch {
|
|
return item.link;
|
|
}
|
|
}
|
|
|
|
export default rss3;
|