mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 05:03:44 +08:00
feat(core): handle link and pubDate parameter
This commit is contained in:
@@ -26,10 +26,32 @@ module.exports = async (ctx, next) => {
|
||||
ctx.state.data.title && (ctx.state.data.title = he.decode(ctx.state.data.title + ''));
|
||||
ctx.state.data.description && (ctx.state.data.description = he.decode(ctx.state.data.description + ''));
|
||||
|
||||
// handle description
|
||||
// sort items
|
||||
ctx.state.data.item = ctx.state.data.item.sort((a, b) => +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));
|
||||
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
item.title && (item.title = he.decode(item.title + ''));
|
||||
|
||||
// handle pubDate
|
||||
if (item.pubDate) {
|
||||
item.pubDate = new Date(item.pubDate).toUTCString();
|
||||
}
|
||||
|
||||
// handle link
|
||||
if (item.link) {
|
||||
let baseUrl = ctx.state.data.link;
|
||||
if (baseUrl && !baseUrl.match(/^https?:\/\//)) {
|
||||
if (baseUrl.match(/^\/\//)) {
|
||||
baseUrl = 'http:' + baseUrl;
|
||||
} else {
|
||||
baseUrl = 'http://' + baseUrl;
|
||||
}
|
||||
}
|
||||
|
||||
item.link = new URL(item.link, baseUrl).href;
|
||||
}
|
||||
|
||||
// handle description
|
||||
if (item.description) {
|
||||
const $ = cheerio.load(item.description);
|
||||
let baseUrl = item.link || ctx.state.data.link;
|
||||
|
||||
Reference in New Issue
Block a user