rsshub
Version:
Make RSS Great Again!
119 lines (111 loc) • 4.69 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { n as parseRelativeDate, t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { t as fetchArticle } from "./wechat-mp-Dq_pp853.mjs";
import { load } from "cheerio";
//#region lib/routes/oschina/news.ts
const configs = {
all: {
name: "最新资讯",
link: "https://www.oschina.net/news/project",
ajaxUrl: "https://www.oschina.net/news/widgets/_news_index_all_list?p=1&type=ajax"
},
industry: {
name: "综合资讯",
link: "https://www.oschina.net/news/industry",
ajaxUrl: "https://www.oschina.net/news/widgets/_news_index_generic_list?p=1&type=ajax"
},
project: {
name: "软件更新资讯",
link: "https://www.oschina.net/news/project",
ajaxUrl: "https://www.oschina.net/news/widgets/_news_index_project_list?p=1&type=ajax"
},
"industry-news": {
name: "行业资讯",
link: "https://www.oschina.net/news/industry-news",
ajaxUrl: "https://www.oschina.net/news/widgets/_news_index_industry_list?p=1&type=ajax"
},
programming: {
name: "编程语言资讯",
link: "https://www.oschina.net/news/programming",
ajaxUrl: "https://www.oschina.net/news/widgets/_news_index_programming_language_list?p=1&type=ajax"
}
};
const route = {
path: "/news/:category?",
categories: ["programming"],
example: "/oschina/news/project",
parameters: { category: "板块名" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["oschina.net/news/:category"],
target: "/news/:category"
}],
name: "资讯",
maintainers: ["tgly307", "zengxs"],
handler,
description: `| [综合资讯][osc_gen] | [软件更新资讯][osc_proj] | [行业资讯][osc_ind] | [编程语言资讯][osc_pl] |
| ------------------- | ------------------------ | ------------------- | ---------------------- |
| industry | project | industry-news | programming |
订阅 [全部板块资讯][osc_all] 可以使用 [https://rsshub.app/oschina/news](https://rsshub.app/oschina/news)
[osc_all]: https://www.oschina.net/news "开源中国 - 全部资讯"
[osc_gen]: https://www.oschina.net/news/industry "开源中国 - 综合资讯"
[osc_proj]: https://www.oschina.net/news/project "开源中国 - 软件更新资讯"
[osc_ind]: https://www.oschina.net/news/industry-news "开源中国 - 行业资讯"
[osc_pl]: https://www.oschina.net/news/programming "开源中国 - 编程语言资讯"`
};
const getCookie = () => cache_default.tryGet("oschina:cookie", async () => {
return (await ofetch_default.raw("https://www.oschina.net/news")).headers.getSetCookie().map((i) => i.split(";")[0]).join("; ");
}, config.cache.routeExpire, false);
async function handler(ctx) {
const config$1 = configs[ctx.req.param("category") ?? "all"];
const cookie = await getCookie();
const $ = load(await ofetch_default(config$1.ajaxUrl, { headers: {
Referer: config$1.link,
"X-Requested-With": "XMLHttpRequest",
Cookie: cookie
} }));
$(".ad-wrap").remove();
const list = $(".items .news-item").toArray().map((item) => {
item = $(item);
const date = item.find(".extra > .list > .item:nth-of-type(2)").text();
return {
title: item.find("h3 a").attr("title"),
description: item.find(".description p").text(),
link: item.find("h3 a").attr("href"),
pubDate: timezone(/\//.test(date) ? parseDate(date, ["YYYY/MM/DD HH:mm", "MM/DD HH:mm"]) : parseRelativeDate(date), 8)
};
});
const resultItem = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
if (/^https?:\/\/(my|www)\.oschina.net\/.*$/.test(item.link)) {
const content = load(await ofetch_default(item.link, { headers: {
Referer: config$1.link,
Cookie: cookie
} }));
content(".ad-wrap").remove();
item.description = content(".article-detail").html();
item.author = content(".article-box__meta .item").first().text();
} else if (/^https?:\/\/gitee\.com\/.*$/.test(item.link)) item.description = load(await ofetch_default(item.link, { headers: { Referer: config$1.link } }))(".file_content").html();
else if (/^https?:\/\/osc\.cool\/.*$/.test(item.link)) return fetchArticle(item.link, true);
return item;
})));
return {
title: `开源中国-${config$1.name}`,
link: config$1.link,
item: resultItem
};
}
//#endregion
export { route };