rsshub
Version:
Make RSS Great Again!
52 lines (51 loc) • 1.59 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs";
import { load } from "cheerio";
//#region lib/routes/meihua/article.ts
const config = {
latest: {
link: "article!2",
title: "最新"
},
hot: {
link: "article!3",
title: "热门"
}
};
const route = {
path: "/article/:caty",
categories: ["new-media"],
example: "/meihua/article/latest",
parameters: { caty: "分类,见下表" },
name: "文章",
maintainers: ["nczitzk"],
description: `| 最新 | 热门 |
| ------ | ---- |
| latest | hot |`,
handler
};
async function handler(ctx) {
const { caty } = ctx.req.param();
const cfg = config[caty];
if (!cfg) throw new InvalidParameterError(`Bad category: ${caty}`);
const currentUrl = `https://www.meihua.info/${cfg.link}`;
const response = await rofetch(currentUrl);
const shotList = JSON.parse(response.match(/"compositionStore":(.*?),"detailStore":/)[1]).compositionsData.list.map((item) => ({
title: item.title,
link: `https://www.meihua.info/article/${item.compositionId}`,
pubDate: parseDate(item.gmtPublish)
}));
const items = await Promise.all(shotList.map((item) => cache_default.tryGet(item.link, async () => {
item.description = load(await rofetch(item.link))("#article-content-html").html();
return item;
})));
return {
title: `${cfg.title}文章 - 梅花网`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };