UNPKG

rsshub

Version:
75 lines (73 loc) 2.08 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { load } from "cheerio"; //#region lib/routes/asianfanfics/tag.ts const route = { path: "/tag/:tag/:type", categories: ["reading"], example: "/asianfanfics/tag/milklove/N", parameters: { tag: "标签", type: "排序类型" }, name: "标签", maintainers: ["KazooTTT"], radar: [{ source: ["www.asianfanfics.com/browse/tag/:tag/:type"], target: "/tag/:tag/:type" }], description: `匹配asianfanfics标签,支持排序类型: - L: Latest 最近更新 - N: Newest 最近发布 - O: Oldest 最早发布 - C: Completed 已完成 - OS: One Shots 短篇 `, handler }; const typeToText = { L: "最近更新", N: "最近发布", O: "最早发布", C: "已完成", OS: "短篇" }; async function handler(ctx) { const tag = ctx.req.param("tag"); const type = ctx.req.param("type"); if (!type || ![ "L", "N", "O", "C", "OS" ].includes(type)) throw new Error("无效的排序类型"); const link = `https://www.asianfanfics.com/browse/tag/${tag}/${type}`; const $ = load(await ofetch_default(link, { headers: { "user-agent": config.trueUA, Referer: "https://www.asianfanfics.com/" } })); const items = $(".primary-container .excerpt").toArray().filter((element) => { return $(element).find(".excerpt__title a").length > 0; }).map((element) => { const $element = $(element); return { title: $element.find(".excerpt__title a").text(), link: "https://www.asianfanfics.com" + $element.find(".excerpt__title a").attr("href"), author: $element.find(".excerpt__meta__name a").text().trim(), pubDate: parseDate($element.find("time").attr("datetime") || ""), description: $element.find(".excerpt__text").html() }; }); return { title: `Asianfanfics - 标签:${tag} - ${typeToText[type]}`, link, item: items }; } //#endregion export { route };