UNPKG

rsshub

Version:
77 lines (75 loc) 3.11 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/6park/news.ts const route = { path: "/news/:site?/:id?/:keyword?", radar: [{ source: ["club.6parkbbs.com/:id/index.php", "club.6parkbbs.com/"], target: "/:id?" }], name: "新闻栏目", maintainers: ["nczitzk", "cscnk52"], parameters: { site: "分站,可选newspark、local,默认为 newspark", id: "栏目 id,可选,默认为空", keyword: "关键词,可选,默认为空" }, description: `::: tip 提示 若订阅 [时政](https://www.6parknews.com/newspark/index.php?type=1),其网址为 <https://www.6parknews.com/newspark/index.php?type=1>,其中 \`newspark\` 为分站,\`1\` 为栏目 id。 若订阅 [美国](https://local.6parknews.com/index.php?type_id=1),其网址为 <https://local.6parknews.com/index.php?type_id=1>,其中 \`local\` 为分站,\`1\` 为栏目 id。 :::`, handler }; async function handler(ctx) { const site = ctx.req.param("site") ?? "newspark"; const id = ctx.req.param("id") ?? ""; const keyword = ctx.req.param("keyword") ?? ""; const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 50; const isLocal = site === "local"; const rootUrl = `https://${isLocal ? site : "www"}.6parknews.com`; const currentUrl = `${`${rootUrl}${isLocal ? "" : "/newspark"}/index.php`}${keyword ? `?act=newssearch&app=news&keywords=${keyword}&submit=查询` : id ? Number.isNaN(id) ? `?act=${id}` : isLocal ? `?type_id=${id}` : `?type=${id}` : ""}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $("#d_list ul li, #thread_list li, .t_l .t_subject").toArray().slice(0, limit).map((item) => { item = $(item); const a = item.find("a").first(); const link = a.attr("href"); return { title: a.text(), link: link.startsWith("http") ? link : `${rootUrl}/${link.startsWith("view") ? `newspark/${link}` : link}` }; }); items = await Promise.all(items.filter((item) => /6parknews\.com/.test(item.link)).map((item) => cache_default.tryGet(item.link, async () => { try { const detailResponse = await got_default({ method: "get", url: item.link }); const content = load(detailResponse.data); const matches = detailResponse.data.match(/新闻来源:(.*?)于.*(\d{4}(?:-\d{2}){2} (?:\d{1,2}:){2}\d{1,2})/); item.title = content("h2").text(); item.author = matches[1].trim(); item.pubDate = timezone(parseDate(matches[2], "YYYY-MM-DD h:m"), 8); item.description = content("#shownewsc").html().replaceAll("<p></p>", ""); } catch {} return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };