rsshub
Version:
Make RSS Great Again!
50 lines (49 loc) • 2.02 kB
JavaScript
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs";
import { t as cache_default } from "./cache-C1Y-9qDV.mjs";
import { load } from "cheerio";
//#region lib/routes/deloitte/industries.ts
const route = {
path: "/industries/:category?",
categories: ["journal"],
example: "/deloitte/industries/consumer",
parameters: { category: "默认为 energy" },
name: "Articles",
maintainers: ["laampui"],
description: `| 消费行业 | 能源、资源及工业行业 | 金融服务行业 | 政府及公共服务 | 生命科学与医疗 | 科技、传媒及电信行业 |
| -------- | -------------------- | ------------------ | ----------------- | ------------------------- | -------------------- |
| consumer | energy | financial-services | government-public | life-sciences-health-care | tmt |`,
handler
};
async function handler(ctx) {
const { category = "energy" } = ctx.req.param();
const rootUrl = "https://www.deloitte.com";
const currentUrl = `${rootUrl}/cn/zh/Industries/${category}/about.html`;
const response = await rofetch(currentUrl);
const $ = load(response);
const cells = $(".cmp-mosaic-grid__cell");
const articles = cells.length ? cells.toArray().map((ele) => {
const $ele = $(ele);
return {
title: $ele.find(".cmp-mosaic-grid__title h4").text(),
link: new URL($ele.find("a").attr("href"), rootUrl).href
};
}) : $(".cmp-promo-container__content a.cmp-promo-tracking").toArray().map((ele) => {
const $ele = $(ele);
return {
title: $ele.find(".cmp-promo__content__title").text().trim(),
link: new URL($ele.attr("href"), rootUrl).href
};
});
const item = await Promise.all(articles.map((item) => cache_default.tryGet(item.link, async () => {
const detailResponse = await rofetch(item.link);
item.description = load(detailResponse)(".cmp-text").html();
return item;
})));
return {
title: `Deloitte - ${$("title").text().split("|", 1)[0].trim()}`,
link: currentUrl,
item
};
}
//#endregion
export { route };