UNPKG

rsshub

Version:
78 lines (76 loc) 2.31 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"; //#region lib/routes/openrice/offers.ts init_esm_shims(); const baseUrl = "https://www.openrice.com"; const route = { path: "/:lang/hongkong/offers", maintainers: ["after9"], handler, categories: ["shopping"], example: "/openrice/zh/hongkong/offers", parameters: { lang: "语言,缺省为 zh" }, name: "香港餐廳精選優惠券", description: ` | 简体 | 繁體 | EN | | ----- | ------ | ----- | | zh-cn | zh | en | ` }; async function handler(ctx) { const lang = ctx.req.param("lang") ?? "zh"; const apiPath = "/api/offers"; let urlPath; switch (lang) { case "zh-cn": urlPath = "/zh-cn/hongkong/offers"; break; case "en": urlPath = "/en/hongkong/offers"; break; case "zh": default: urlPath = "/zh/hongkong/offers"; break; } const response = await ofetch_default(baseUrl + apiPath, { headers: { accept: "application/json" }, query: { uiLang: lang, uiCity: "hongkong", page: 1, sortBy: "PublishTime", couponTypeId: 1 } }); const pageInfo = response.pageInfo; const highlightedOffers = response.highlightedOffers; const normalOffers = response.searchResult.paginationResult.results; const resultList = [...highlightedOffers, ...normalOffers].map((item) => { const title = item.title ?? ""; const link = baseUrl + item.urlUI; const coverImg = item.doorPhotoUI.urls.full ?? ""; const descriptionText = item.couponType === 0 ? item.poiNameUI : `${item.desc} (${item.startTimeUI} - ${item.expireTimeUI}) [${item.multiplePoiDistrictName}]`; return { title, description: art(path.join(__dirname, "templates/description-89cc7c28.art"), { description: descriptionText, image: coverImg }), link }; }); return { title: pageInfo.seoInfo.title ?? "OpenRice Hong Kong Offers", link: baseUrl + urlPath, description: pageInfo.seoInfo.metadataDictionary.name.find((item) => item.key === "description")?.value ?? "OpenRice Hong Kong Offers", item: resultList }; } //#endregion export { route };