UNPKG

rsshub

Version:
92 lines (89 loc) 2.81 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs"; import { t as isValidHost } from "./valid-host-BH9Dd2Pf.mjs"; import { load } from "cheerio"; //#region lib/routes/bendibao/news.ts const route = { path: "/news/:city", categories: ["new-media"], example: "/bendibao/news/bj", parameters: { city: "城市缩写,可在该城市页面的 URL 中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["bendibao.com/"] }], name: "焦点资讯", maintainers: ["nczitzk"], handler, url: "bendibao.com/", description: `| 城市名 | 缩写 | | ------ | ---- | | 北京 | bj | | 上海 | sh | | 广州 | gz | | 深圳 | sz | 更多城市请参见 [这里](http://www.bendibao.com/city.htm) > **香港特别行政区** 和 **澳门特别行政区** 的本地宝城市页面不更新资讯。` }; async function handler(ctx) { const city = ctx.req.param("city"); if (!isValidHost(city)) throw new InvalidParameterError("Invalid city"); const rootUrl = `http://${city}.bendibao.com`; let response = await got_default({ method: "get", url: rootUrl }); let $ = load(response.data); const title = $("title").text().replace(/-爱上本地宝,生活会更好/, "") + "焦点资讯"; let items = $("ul.focus-news li").toArray().map((item) => { const $item = $(item).find("a"); const link = $item.attr("href"); return { title: $item.text(), link: link.startsWith("http") ? link : `${rootUrl}${link}` }; }); if (!items.length) { response = await got_default({ method: "get", url: `http://${city}.bendibao.com/news` }); $ = load(response.data); items = $("#listNewsTimeLy div.info").toArray().map((item) => { const $item = $(item).find("a"); const link = $item.attr("href"); return { title: $item.text(), link: link.startsWith("http") ? link : `${rootUrl}${link}` }; }); } items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { try { const content = load((await got_default({ method: "get", url: item.link })).data); item.description = content("div.content").html() ?? content("div.content-box").html(); item.pubDate = timezone(parseDate(content("span.time").text().replace(/发布时间:/, "") ?? content("span.public_time").text()), 8); return item; } catch { return ""; } }))); return { title, link: rootUrl, item: items }; } //#endregion export { route };