UNPKG

rsshub

Version:
61 lines (60 loc) 2.13 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import "./types-DNj6Etbg.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { load } from "cheerio"; //#region lib/routes/acfun/user-article.ts const host = "https://www.acfun.cn"; const route = { path: "/user/article/:uid", radar: [{ source: ["www.acfun.cn/u/:id"], target: "/user/article/:id" }], name: "用户文章", parameters: { uid: "用户 UID" }, categories: ["anime"], example: "/acfun/user/article/1384329", view: 0, maintainers: ["tiaod"], handler }; async function handler(ctx) { const uid = ctx.req.param("uid"); const link = `${host}/u/${uid}`; const page = await rofetch(link); const $ = load(page); const username = $("#ac-space-info .name").first().text().trim(); const description = $(".signature .complete").text(); const image = $("head style:contains(\"user-photo\")").text().match(/.user-photo\{\n\s*background:url\((.*)\) 0% 0% \/ 100% no-repeat;/)?.[1]; const list = $("#ac-space-article-list .weblog-item").toArray().map((item) => { const $item = $(item); const $title = $item.find("a.title"); const itemDate = $item.find(".info").text().match(/\d{4}\/\d{1,2}\/\d{1,2}/)?.[0]; return { title: $title.text(), link: `${host}${$title.attr("href")}`, pubDate: itemDate ? parseDate(itemDate, "YYYY/MM/DD") : void 0 }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const articlePage = await rofetch(item.link, { headers: { referer: link } }); const articleInfo = load(articlePage)(".main script").text().match(/window\.articleInfo = (.*);\n\s*window.likeDomain/)[1]; const data = JSON.parse(articleInfo); return { ...item, description: data.parts[0].content, author: data.user?.name, category: [...data.channel?.name ? [data.channel.name] : [], ...(data.tagList ?? []).map((tag) => tag.name)] }; }))); return { title: username ? `${username}的文章` : $("title").text(), link, description, image, item: items }; } //#endregion export { route };