UNPKG

rsshub

Version:
52 lines (51 loc) 1.79 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as config } from "./config-BfTrYkQS.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as ConfigNotFoundError } from "./config-not-found-fQ5mxvDU.mjs"; import { load } from "cheerio"; //#region lib/routes/hexo/next.ts const route = { path: "/next/:url", categories: ["blog"], example: "/hexo/next/archive.diygod.me", parameters: { url: "the blog URL without the protocol (http:// and https://)" }, name: "Blog using Next theme", maintainers: ["fengkx"], features: { requireConfig: [{ name: "ALLOW_USER_SUPPLY_UNSAFE_DOMAIN", description: "Allow user supplied domain" }] }, handler }; async function handler(ctx) { if (!config.feature.allow_user_supply_unsafe_domain) throw new ConfigNotFoundError(`This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); const url = `http://${ctx.req.param("url")}`; const res = await rofetch(`${url}/archives/`); const $ = load(res); const list = $(".post-header").slice(0, 5).toArray().map((element) => { const each = $(element); const storyLink = each.find(".post-title-link").attr("href"); return { title: each.find("[itemprop=name]").text(), link: new URL(storyLink, url).href }; }); const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const storyDetail = await rofetch(item.link); const $ = load(storyDetail); return { ...item, pubDate: parseDate($("time").attr("datetime")), description: $(".post-body").html() }; }))); return { title: $(".site-title").text(), link: url, description: $("[name=description]").attr("content"), item: out }; } //#endregion export { route };