rsshub
Version:
Make RSS Great Again!
64 lines (62 loc) • 1.82 kB
JavaScript
import "./dist-Bog6z_OM.mjs";
import "./config-MQ-7ebJ_.mjs";
import "./logger-C4avouvV.mjs";
import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs";
import { t as renderDescription } from "./description-IhF8MX6U.mjs";
import { load } from "cheerio";
//#region lib/routes/openrice/promos.ts
const baseUrl = "https://www.openrice.com";
const route = {
path: "/:lang/hongkong/promos",
maintainers: ["after9"],
handler,
categories: ["shopping"],
example: "/openrice/zh/hongkong/promos",
parameters: { lang: "语言,缺省为 zh" },
name: "香港餐厅滋讯",
description: `
| 简体 | 繁體 | EN |
| ----- | ------ | ----- |
| zh-cn | zh | en |
`
};
async function handler(ctx) {
const lang = ctx.req.param("lang") ?? "zh";
let urlPath;
switch (lang) {
case "zh-cn":
urlPath = "/zh-cn/hongkong/promos";
break;
case "en":
urlPath = "/en/hongkong/promos";
break;
default:
urlPath = "/zh/hongkong/promos";
break;
}
const $ = load(await ofetch_default(baseUrl + urlPath, {}));
const title = $("title").text() ?? "Openrice - What's Hot";
const description = $("meta[name=\"description\"]").attr("content") ?? "What's Hot from Openrice";
const resultList = $(".article-listing-content-cell-wrapper").toArray().map((item) => {
const $item = $(item);
const title = $item.find(".title-name").text() ?? "";
const link = $item.find("a.sr1-listing-content-cell").attr("href") ?? "";
const coverImg = $item.find(".cover-photo").attr("style")?.match(/url\(['"]?(.*?)['"]?\)/)?.[1] ?? null;
return {
title,
description: renderDescription({
description: $item.find(".article-details .desc").text() ?? "",
image: coverImg
}),
link
};
});
return {
title,
link: baseUrl + urlPath,
description,
item: resultList
};
}
//#endregion
export { route };