UNPKG

rsshub

Version:
80 lines (78 loc) 3.11 kB
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 parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { load } from "cheerio"; //#region lib/routes/uber/blog.ts const rootURL = "https://www.uber.com"; const route = { path: "/blog/:compat?", categories: ["blog"], example: "/uber/blog", features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.uber.com/:language/blog/engineering"], target: "/blog" }], name: "Engineering", maintainers: ["hulb"], handler, url: "www.uber.com/en-HK/blog/engineering", description: "The English blog on any of Uber's regional sites (e.g., www.uber.com/en-JP/blog) is the same engineering blog provided by this route, so language selection is not supported. This route is not for the public news blog on specific regional sites (e.g., www.uber.com/ja-JP/blog).", zh: { description: "uber的任何区域站点的英文blog(例如www.uber.com/en-JP/blog)都是相同的内容,正是本路由提供的engineering blog,因此本路由不提供语言选择;本路由不是uber在特定区域站点的公开新闻blog(例如www.uber.com/ja-JP/blog)" } }; async function handler() { const $ = load(await ofetch_default(`${rootURL}/en-HK/blog/engineering/rss/`, { headers: { accept: "text/html" }, parseResponse: (txt) => txt }), { xmlMode: true }); const result = await Promise.all($("item").toArray().map((el) => cache_default.tryGet($(el).find("link").text(), async () => { const scriptText = load(await ofetch_default($(el).find("link").text(), { headers: { accept: "text/html" } }))("script#__REDUX_STATE__").text().trim(); const jsonText = decodeURIComponent(JSON.parse(`"${scriptText}"`)); const contentHtml = findNode(JSON.parse(jsonText), { idKey: "id", idValue: "BlogArticleContent", siblingKey: "props", childKey: "content" }).replaceAll(String.raw`\n`, ""); return { link: $(el).find("link").text(), title: $(el).find("title").text(), description: contentHtml, pubDate: parseDate($(el).find("pubDate").text()), category: $(el).find("category").toArray().map((item) => $(item).text()) }; }))); return { title: `Uber Engineering Blog`, link: rootURL + "/blog/engineering", description: "The technology behind Uber Engineering", item: result }; } function findNode(json, options) { const { idKey = "id", idValue, siblingKey, childKey } = options; if (Array.isArray(json)) for (const item of json) { const result = findNode(item, options); if (result !== void 0) return result; } else if (json && typeof json === "object") { if (json[idKey] === idValue) return json[siblingKey]?.[childKey]; for (const key in json) { const result = findNode(json[key], options); if (result !== void 0) return result; } } } //#endregion export { route };