UNPKG

rsshub

Version:
53 lines (51 loc) 2.15 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 { load } from "cheerio"; //#region lib/routes/web3caff/index.ts const route = { path: "/:path{.+}?", categories: ["new-media"], example: "/web3caff/zh/archives/category/news_zh", parameters: { path: "路径,默认为首页" }, name: "发现", maintainers: ["nczitzk"], description: `路径处填写对应页面 URL 中 \`https://web3caff.com/\` 后的字段。下面是一个例子。 若订阅 [叙事 - Web3Caff](https://web3caff.com/zh/archives/category/news_zh) 则将对应页面 URL <https://web3caff.com/zh/archives/category/news_zh> 中 \`https://web3caff.com/\` 后的字段 \`zh/archives/category/news_zh\` 作为路径填入。此时路由为 [\`/web3caff/zh/archives/category/news_zh\`](https://rsshub.app/web3caff/zh/archives/category/news_zh)`, handler }; async function handler(ctx) { const path = ctx.req.param("path"); const rootUrl = "https://web3caff.com"; const currentUrl = path ? `${rootUrl}/${path}` : rootUrl; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $(".list-grouped").first().find(".list-body").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 10).toArray().map((item) => { const a = $(item).find(".list-title"); return { title: a.text(), link: a.attr("href") }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content(".ss-inline-share-wrapper").remove(); item.description = content(".post-content").html(); item.author = content(".author-name .author-popup").text(); item.category = content("a[rel=\"category tag\"]").toArray().map((tag) => $(tag).text()); item.pubDate = parseDate(content("meta[property=\"article:published_time\"]").attr("content")); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };