rsshub
Version:
Make RSS Great Again!
99 lines (95 loc) • 3 kB
JavaScript
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 { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import { t as isValidHost } from "./valid-host-C-u5eW3j.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 invalid_parameter_default("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) => {
item = $(item).find("a");
const link = item.attr("href");
return {
title: item.text(),
link: link.indexOf("http") === 0 ? 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) => {
item = $(item).find("a");
const link = item.attr("href");
return {
title: item.text(),
link: link.indexOf("http") === 0 ? 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 };