UNPKG

rsshub

Version:
50 lines (49 loc) 1.74 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as config } from "./config-Bpyy15zS.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.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 $ = load(await rofetch(`${url}/archives/`)); 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 $ = load(await rofetch(item.link)); 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 };