UNPKG

rsshub

Version:
71 lines (68 loc) 2.75 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./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 "./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/elasticsearch-cn/index.ts const route = { path: "/:params?", categories: ["bbs"], example: "/elasticsearch-cn", parameters: { params: "分类,可在对应分类页 URL 中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["elasticsearch.cn/:params", "elasticsearch.cn/"], target: "/:params" }], name: "发现", maintainers: ["nczitzk"], handler, description: `如 [Elasticsearch 最新](https://elasticsearch.cn/category-2) 的 URL 为 \`https://elasticsearch.cn/category-2\`,则分类参数处填写 \`category-2\`,最后得到路由地址 [\`/elasticsearch-cn/category-2\`](https://rsshub.app/elasticsearch-cn/category-2)。 又如 [求职招聘 30 天热门](https://elasticsearch.cn/sort_type-hot____category-12__day-30) 的 URL 为 \`https://elasticsearch.cn/sort_type-hot____category-12__day-30\`,则分类参数处填写 \`sort_type-hot____category-12__day-30\`,最后得到路由地址 [\`/elasticsearch-cn/sort_type-hot____category-12__day-30\`](https://rsshub.app/elasticsearch-cn/sort_type-hot____category-12__day-30)。` }; async function handler(ctx) { const params = ctx.req.param("params") ?? ""; const currentUrl = `https://elasticsearch.cn${params ? `/${params}` : ""}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $(".aw-question-content").toArray().map((item) => { item = $(item); const a = item.find("h4 a"); const pubDate = item.find("span.text-color-999").not(".pull-right").first().text().split("•").pop().trim(); return { title: a.text(), link: a.attr("href"), author: item.find(".aw-user-name").text(), pubDate: timezone(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(pubDate) ? parseDate(pubDate) : parseRelativeDate(pubDate), 8) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { item.description = load((await got_default({ method: "get", url: item.link })).data)(".markitup-box").first().html(); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };