UNPKG

rsshub

Version:
38 lines (37 loc) 1.32 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { load } from "cheerio"; //#region lib/routes/wangwusiwj/index.ts const route = { path: "/:id?", categories: ["blog"], example: "/wangwusiwj", parameters: { id: "RSS 抓取地址:https://wangwusiwj.blogspot.com/:id?,默认为当前年份" }, name: "文章", maintainers: ["prnake"], handler }; async function handler(ctx) { const { id = String((/* @__PURE__ */ new Date()).getFullYear()) } = ctx.req.param(); const url = `https://wangwusiwj.blogspot.com/${id}`; const [response, sitemap] = await Promise.all([rofetch(url), rofetch("https://wangwusiwj.blogspot.com/sitemap.xml", { responseType: "text" })]); const $ = load(response); const $sitemap = load(sitemap, { xml: true }); const pubDates = new Map($sitemap("url").toArray().map((e) => [$sitemap(e).find("loc").text(), $sitemap(e).find("lastmod").text()])); return { title: "王五四文集", link: url, item: $("div.post").toArray().map((e) => { const link = $(e).find("h3 > a").attr("href"); return { title: $(e).find("h3 > a").text(), description: $(e).find(".post-body").html(), link, author: "王五四", pubDate: parseDate(pubDates.get(link)) }; }) }; } //#endregion export { route };