UNPKG

rsshub

Version:
52 lines (50 loc) 1.88 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { load } from "cheerio"; //#region lib/routes/gushiwen/recommend.ts const route = { path: "/recommend/:annotation?", categories: ["other"], example: "/gushiwen/recommend/zhushang", parameters: { annotation: "添加哪些附加信息" }, name: "首页推荐", maintainers: ["LogicJake"], description: `\`annotation\` 字段为添加哪些附加信息。可从以下表格中选择值后按顺序拼接。例如如果需要注释和赏析,则为\`zhushang\`。 | 翻译 | 注释 | 赏析 | | ---- | ---- | ----- | | yi | zhu | shang |`, handler }; const idPattern = /230427\('\w+','(\w+)'\)/; function getContent(onclick, annotation) { const id = onclick.match(idPattern)[1]; return rofetch(`https://www.gushiwen.cn/nocdn/ajaxshiwenDetailCont.aspx?id=${id}&value=${annotation}`, { headers: { cookie: "login=flase" } }); } async function handler(ctx) { const url = "https://www.gushiwen.cn/"; const res = await rofetch(url); const { annotation } = ctx.req.param(); const $ = load(res); return { title: "古诗文推荐", link: url, item: await Promise.all($("div.sons:has(div.contson)").slice(0, 10).toArray().map((item) => { const $item = $(item); const href = $item.find("p a").attr("href"); const link = href ? new URL(href, url).href : void 0; return cache_default.tryGet(`gushiwen:recommend:${link}:${annotation ?? ""}`, async () => { let description = $item.find("div.contson").html(); const onclick = $item.find("img[onclick]").attr("onclick"); if (annotation && onclick) description = await getContent(onclick, annotation); return { title: $item.find("b").text(), link, description, author: $item.find("p.source").text() }; }); })) }; } //#endregion export { route };