rsshub
Version:
Make RSS Great Again!
51 lines (49 loc) • 1.82 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import { t as isValidHost } from "./valid-host-C-u5eW3j.mjs";
import { load } from "cheerio";
import markdownit from "markdown-it";
//#region lib/routes/hedwig/posts.ts
const md = markdownit({ html: true });
const route = {
path: "/posts/:site",
categories: ["blog"],
example: "/posts/walnut",
parameters: { site: "站点名,原则上只要是 `{site}.hedwig.pub` 都可以匹配" },
features: { supportRadar: false },
name: "Posts",
url: "hedwig.pub",
maintainers: ["zwithz", "GetToSet"],
view: ViewType.Articles,
handler: async (ctx) => {
const { site } = ctx.req.param();
if (!isValidHost(site)) throw new invalid_parameter_default("Invalid site");
const baseUrl = `https://${site}.hedwig.pub`;
const text = load(await ofetch_default(baseUrl))("script#__NEXT_DATA__").text();
const pageProps = JSON.parse(text).props.pageProps;
const list = pageProps.issuesByNewsletter.map((item) => {
const description = item.blocks.reduce((desc, block) => desc + md.render(block.markdown.text), "");
return {
title: item.subject,
description,
pubDate: timezone(parseDate(item.publishAt, "YYYY-MM-DDTHH:mm:ss.SSS[Z]"), 0),
link: `${baseUrl}/i/${item.urlFriendlyName}`
};
});
return {
title: pageProps.newsletter.name,
description: pageProps.newsletter.about,
link: baseUrl,
item: list
};
}
};
//#endregion
export { route };