rsshub
Version:
Make RSS Great Again!
78 lines (75 loc) • 2.79 kB
JavaScript
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as parser } from "./rss-parser-CmTb9lkc.mjs";
import { n as fetchBbcContent } from "./utils-BZMQJ2ni.mjs";
//#region lib/routes/bbc/index.ts
const route = {
path: "/:site?/:channel?",
name: "News",
maintainers: [
"HenryQW",
"DIYgod",
"pseudoyu"
],
handler,
example: "/bbc/world-asia",
parameters: {
site: "语言,简体或繁体中文",
channel: "channel, default to `top stories`"
},
categories: ["traditional-media"],
description: `Provides a better reading experience (full text articles) over the official ones.
Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/10628494). Eg, \`business\` for \`https://feeds.bbci.co.uk/news/business/rss.xml\`.
- Channel contains sub-directories, such as \`https://feeds.bbci.co.uk/news/world/asia/rss.xml\`, replace \`/\` with \`-\`, \`/bbc/world-asia\`.`
};
async function handler(ctx) {
let feed, title, link;
const { site, channel } = ctx.req.param();
if (site) switch (site.toLowerCase()) {
case "chinese":
title = "BBC News 中文网";
feed = await (channel ? parser.parseURL(`https://www.bbc.co.uk/zhongwen/simp/${channel}/index.xml`) : parser.parseURL("https://www.bbc.co.uk/zhongwen/simp/index.xml"));
break;
case "traditionalchinese":
title = "BBC News 中文網";
feed = await (channel ? parser.parseURL(`https://www.bbc.co.uk/zhongwen/trad/${channel}/index.xml`) : parser.parseURL("https://www.bbc.co.uk/zhongwen/trad/index.xml"));
link = "https://www.bbc.com/zhongwen/trad";
break;
default:
feed = await parser.parseURL(`https://feeds.bbci.co.uk/news/${site.split("-").join("/")}/rss.xml`);
title = `BBC News ${site}`;
link = `https://www.bbc.co.uk/news/${site.split("-").join("/")}`;
break;
}
else {
feed = await parser.parseURL("https://feeds.bbci.co.uk/news/rss.xml");
title = "BBC News Top Stories";
link = "https://www.bbc.co.uk/news";
}
const items = await Promise.all(feed.items.filter((item) => item && item.link).map((item) => {
const link = item.link.split("?", 1)[0];
return {
...item,
link: site === "chinese" ? item.link.replace("/trad", "/simp") : link
};
}).map((item) => cache_default.tryGet(item.link, async () => {
const linkURL = new URL(item.link);
if (linkURL.hostname === "www.bbc.com") linkURL.hostname = "www.bbc.co.uk";
const { category, description } = await fetchBbcContent(linkURL.href, item);
return {
title: item.title || "",
description: description || "",
pubDate: item.pubDate,
link: item.link,
category: category ?? item.categories ?? []
};
})));
return {
title,
link,
image: "https://www.bbc.com/favicon.ico",
description: title,
item: items
};
}
//#endregion
export { route };