UNPKG

rsshub

Version:
68 lines (66 loc) 2 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/openrice/promos.ts init_esm_shims(); 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; case "zh": 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$1 = $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: title$1, description: art(path.join(__dirname, "templates/description-89cc7c28.art"), { description: $item.find(".article-details .desc").text() ?? "", image: coverImg }), link }; }); return { title, link: baseUrl + urlPath, description, item: resultList }; } //#endregion export { route };