UNPKG

rsshub

Version:
65 lines (62 loc) 2.35 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/chart.ts init_esm_shims(); const baseUrl = "https://www.openrice.com"; const route = { path: "/:lang/hongkong/explore/chart/:category", maintainers: ["after9"], handler, categories: ["shopping"], example: "/openrice/zh/hongkong/explore/chart/most-bookmarked", parameters: { lang: "语言,缺省为 zh", category: "类别,缺省为 most-bookmarked" }, name: "香港餐廳排行榜", description: ` | 简体 | 繁體 | EN | | ----- | ------ | ----- | | zh-cn | zh | en | | 最多收藏 | 每周最高评分 | 最高浏览 | 最佳甜品餐厅 | | ----- | ------ | ----- | ----- | | most-bookmarked | best-rating | most-popular | best-dessert | ` }; async function handler(ctx) { const urlPath = `/${ctx.req.param("lang") ?? "zh"}/hongkong/explore/chart/${ctx.req.param("category") ?? "most-bookmarked"}`; const $ = load(await ofetch_default(baseUrl + urlPath)); const title = $("title").text() ?? "Hong Kong Restaurant Chart"; const description = $("title").text() ?? "Hong Kong Restaurant Chart"; const resultList = $(".poi-chart-main-grid-item-desktop-wrapper").toArray().map((item) => { const $item = $(item); const rankNumber = $item.find(".rank-icon").attr("class")?.match(/rank-(\d+)/)?.[1] ?? ""; const desTagsArray = $item.find(".pcmgidtr-left-section-poi-info-details .pcmgidtrls-poi-info-details-text").toArray().map((tag) => $(tag).text()); const title$1 = $item.find(".pcmgidtr-left-section-poi-info-name .link").text() ?? ""; const link = $item.find(".pcmgidtr-left-section-poi-info-name .link").attr("href") ?? ""; const coverImg = $item.find(".pcmgidtr-left-section-door-photo img").attr("src") ?? null; return { title: title$1, description: art(path.join(__dirname, "templates/chart-4d0fc4e6.art"), { description: desTagsArray ?? [], rankNumber, image: coverImg }), link }; }); return { title, link: baseUrl + urlPath, description, item: resultList }; } //#endregion export { route };