UNPKG

rsshub

Version:
72 lines (70 loc) 2.54 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 "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/idaily/index.ts init_esm_shims(); const route = { path: ["/:language?"], name: "每日环球视野", example: "/idaily", maintainers: ["zphw", "nczitzk"], parameters: { language: "语言,见下表,默认为简体中文" }, radar: [{ source: ["idai.ly/"] }], handler, description: `| 简体中文 | 繁体中文 | | -------- | -------- | | zh-hans | zh-hant |` }; async function handler(ctx) { const { language = "zh-hans" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 100; const apiUrl = new URL(`api/list/v3/iphone/${language}`, "https://idaily-cdn.idailycdn.com").href; const currentUrl = "https://idai.ly"; const { data: response } = await got_default(apiUrl); const items = response.filter((item) => item.ui_sets?.caption_subtitle).slice(0, limit).map((item) => { const image$1 = item.ui_sets?.cover_landscape_hd_4k ?? item.cover_landscape_hd; return { title: `${item.ui_sets?.caption_subtitle} - ${item.title}`, link: item.link_share, description: art(path.join(__dirname, "templates/description-2f40bb93.art"), { images: image$1 ? [{ src: image$1, alt: item.ui_sets?.caption_subtitle ?? item.title }] : void 0, intro: item.content }), author: item.location, category: item.tags?.map((c) => c.name), guid: `idaily-${item.guid}`, pubDate: parseDate(item.pubdate_timestamp, "X"), updated: parseDate(item.lastupdate_timestamp, "X"), enclosure_url: image$1, enclosure_type: `image/${image$1.split(/\./).pop()}` }; }); const { data: currentResponse } = await got_default(currentUrl); const $ = load(currentResponse); const title = $("title").text(); const image = new URL("img/idaily/logo_2x.png", currentUrl).href; return { item: items, title, link: currentUrl, description: $("meta[name=\"description\"]").prop("content"), language: "zh", image, subtitle: $("meta[name=\"keywords\"]").prop("content"), author: title.split(/\s/)[0], allowEmpty: true }; } //#endregion export { route };