rsshub
Version:
Make RSS Great Again!
42 lines (41 loc) • 1.65 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 { load } from "cheerio";
//#region lib/routes/mcdonalds/cn-news.ts
const route = {
path: "/cn/:category",
categories: ["shopping"],
example: "/mcdonalds/cn/sales+event",
parameters: { category: "分类名(可用 + 连接多个分类)" },
name: "麦当劳活动资讯",
maintainers: ["huyyi"],
description: `| 全部分类 | 社会责任 | 人员品牌 | 产品故事 | 优惠 | 品牌文化 | 活动速报 |
| ---------- | -------------- | -------- | -------- | ----- | -------- | -------- |
| news\\_list | responsibility | brand | product | sales | culture | event |`,
handler
};
async function handler(ctx) {
const { category = "news_list" } = ctx.req.param();
const categories = category.split("+");
const baseUrl = "https://www.mcdonalds.com.cn/news/";
const newsLists = await Promise.all(categories.map(async (cate) => {
const $ = load(await rofetch(baseUrl + cate));
return $(".news_list .box-container > div").slice(0, 10).toArray().map((item) => $(item).find("a[target]").attr("href")).filter((href) => href !== void 0);
}));
return {
title: "麦当劳资讯",
link: baseUrl,
item: await Promise.all(newsLists.flat().map((newsUrl) => cache_default.tryGet(newsUrl, async () => {
const $ = load(await rofetch(newsUrl));
return {
title: $("h3").text(),
link: newsUrl,
pubDate: parseDate($("h3 ~ time").text()),
description: $(".cmsPage").html()
};
})))
};
}
//#endregion
export { route };