UNPKG

rsshub

Version:
51 lines (49 loc) 2.12 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import dayjs from "dayjs"; //#region lib/routes/readhub/util.ts init_esm_shims(); const domain = "readhub.cn"; const rootUrl = `https://${domain}`; const apiRootUrl = `https://api.${domain}`; const apiTopicUrl = new URL("topic/list", apiRootUrl).href; const formatDate = (date, format) => dayjs(date).format(format); const toTopicUrl = (id) => new URL(`topic/${id}`, rootUrl).href; art.defaults.imports = { ...art.defaults.imports, formatDate, toTopicUrl }; /** * Process items asynchronously. * * @param {Array<Object>} items - The array of items to process. * @param {function} tryGet - The tryGet function that handles the retrieval process. * @returns {Promise<Array<Object>>} Returns a Promise that resolves to an array of processed items. */ const processItems = async (items, tryGet) => await Promise.all(items.map((item) => tryGet(item.link, async () => { try { if (!item.link.startsWith(rootUrl)) throw new Error(`"${item.link}" is an external URL`); const { data: detailResponse } = await got_default(item.link); const data = JSON.parse(detailResponse.match(/{\\"topic\\":(.*?)}]\\n"]\)<\/script>/)[1].replaceAll(String.raw`\"`, "\"")); item.title = data.title; item.link = data.url ?? new URL(`topic/${data.uid}`, rootUrl).href; item.description = art(path.join(__dirname, "templates/description-71daa88b.art"), { description: data.summary, news: data.newsAggList, timeline: data.timeline }); item.author = data.siteNameDisplay; item.category = [...data.entityList.map((c) => c.name) ?? [], ...data.tagList.map((c) => c.name) ?? []]; item.guid = `readhub-${data.uid}`; item.pubDate = parseDate(data.publishDate.replaceAll(/\s/g, "")); } catch { item.guid = `readhub-${item.guid}`; } return item; }))); //#endregion export { rootUrl as i, apiTopicUrl as n, processItems as r, apiRootUrl as t };