UNPKG

rsshub

Version:
71 lines (69 loc) 1.97 kB
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs"; import { t as config } from "./config-CCmw1BNE.mjs"; import { t as parseDate } from "./parse-date-Cr0wQjV_.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 rofetch(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 };