rsshub
Version:
Make RSS Great Again!
78 lines (76 loc) • 3.23 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { load } from "cheerio";
//#region lib/routes/consumer/shopping-guide.ts
const route = {
path: "/shopping-guide/:category?/:language?",
categories: ["new-media"],
example: "/consumer/shopping-guide",
parameters: {
category: "分类,见下表,默认为 `trivia`",
language: "语言,见上表,默认为 `tc`"
},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "消費全攻略",
maintainers: ["TonyRL"],
handler,
description: `| 冷知識 | 懶人包 | 特集 | 銀髮一族 | 飲食煮意 | 科技達人 | 健康美容 | 規劃人生 | 消閒娛樂 | 家品家電 | 親子時光 | 綠色生活 |
| ------ | ------ | -------- | ------------------ | ---------------- | ---------- | ----------------- | --------------------------- | ------------------------- | --------------- | --------------- | ------------ |
| trivia | tips | features | silver-hair-market | food-and-cooking | tech-savvy | health-and-beauty | life-and-financial-planning | leisure-and-entertainment | home-appliances | family-and-kids | green-living |`
};
async function handler(ctx) {
const { category = "trivia", language = "tc" } = ctx.req.param();
const rootUrl = "https://www.consumer.org.hk";
const currentUrl = `${rootUrl}/${language}/shopping-guide/${category}`;
const { data: response } = await got_default(currentUrl, { headers: { cookie: `consumer_pagination={${encodeURI("\"228c\"")}:24}` } });
const $ = load(response);
const list = $(".shadow-long-blk").toArray().map((item) => {
item = $(item);
const info = item.find(".item-info li").toArray().map((item$1) => $(item$1).text().trim());
return {
title: item.find("h2").text().trim(),
description: item.find("p").text().trim(),
link: `${rootUrl}${item.attr("href")}`,
pubDate: parseDate(info.shift(), "YYYY-MM-DD"),
category: info
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const { data: response$1 } = await got_default(item.link);
const $$1 = load(response$1);
const header = $$1(".article-img-blk");
header.find("img").each((_, ele) => {
ele = $$1(ele);
if (ele.attr("src") && ele.attr("srcset")) {
ele.removeAttr("srcset");
ele.attr("src", ele.attr("src").replace(/\/\d+c\d+\//, "/0p0/"));
}
});
item.description = header.html() + $$1("article .ckec").html();
return item;
})));
return {
title: $("head title").text(),
link: currentUrl,
image: $("meta[property=\"og:image\"]").attr("content"),
logo: $("link[rel=\"apple-touch-icon\"]").attr("href"),
icon: $("link[rel=\"apple-touch-icon\"]").attr("href"),
item: items
};
}
//#endregion
export { route };