rsshub
Version:
Make RSS Great Again!
69 lines (68 loc) • 2.45 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/lifetimes/index.ts
const route = {
path: "/:category?",
categories: ["new-media"],
example: "/lifetimes",
parameters: { category: "栏目,见下表,默认为新闻" },
name: "栏目",
maintainers: ["nczitzk"],
description: `| 新闻 | 医药 | 养生 | 生活 | 母亲行动 | 长寿 | 视频 | 时评 | 调查 | 产业经济 |
| ---- | -------- | --------------- | ---- | -------- | --------- | ----- | ------------ | ------- | -------- |
| news | medicine | healthpromotion | life | mothers | longevity | video | news-comment | hotspot | industry |`,
handler
};
const nodes = {
hotspot: {
title: "调查",
node: "%22/eh78c0d1d%22"
},
industry: {
title: "产业经济",
node: "%22/ehg62mqqm%22"
},
"news-comment": {
title: "本报时评",
node: "%22/egv8vnjpq/egv8vtbcl%22"
}
};
async function handler(ctx) {
const { category = "news" } = ctx.req.param();
const rootUrl = "https://www.lifetimes.cn";
const currentUrl = `${rootUrl}/${category.replace("-", "/")}`;
let title;
let list;
const apiNode = nodes[category];
if (apiNode) {
title = apiNode.title;
list = (await rofetch(`${rootUrl}/api/list?offset=0&limit=20&node=${apiNode.node}`, { parseResponse: JSON.parse })).list.slice(0, 20).map((item) => ({ link: `${rootUrl}/article/${item.aid}` }));
} else {
const $ = load(await rofetch(currentUrl));
title = $("title").text();
$(".oPBlock").remove();
list = $(".list-block ul li, .firstCon-r ul li").find("a").toArray().slice(0, 10).map((item) => ({ link: `https:${$(item).attr("href")}` }));
}
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
try {
const detailResponse = await rofetch(item.link);
const content = load(detailResponse);
item.description = content("article").html();
item.title = content(".container-title").text();
item.author = content(".source").text().replace("来源:", "");
item.pubDate = parseDate(Number.parseInt(detailResponse.match(/\\"ctime\\":(.*),\\"utime\\"/)[1]));
return item;
} catch {
return "";
}
})));
return {
title: `${title} - 生命时报`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };