UNPKG

rsshub

Version:
74 lines (72 loc) 2.05 kB
import "./dist-Bog6z_OM.mjs"; import { t as config } from "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.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 };