UNPKG

rsshub

Version:
64 lines (62 loc) 2.34 kB
import "./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 { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/udn/global/tag.ts const route = { path: "/global/tag/:tag?", categories: ["traditional-media"], example: "/udn/global/tag/過去24小時", parameters: { tag: "标签,可在对应标签页 URL 中找到" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["global.udn.com/search/tagging/1020/:tag", "global.udn.com/"] }], name: "轉角國際 - 標籤", maintainers: ["emdoe", "nczitzk"], handler, description: `| 過去 24 小時 | 鏡頭背後 | 深度專欄 | 重磅廣播 | | ------------ | -------- | -------- | -------- |` }; async function handler(ctx) { const tag = ctx.req.param("tag") ?? "過去24小時"; const rootUrl = "https://global.udn.com"; const currentUrl = `${rootUrl}/search/tagging/1020/${tag}`; let items = (await got_default({ method: "get", url: `${rootUrl}/search/ajax_tag/1020/${tag}` })).data.articles.map((item) => ({ title: item.art_title, link: `${rootUrl}${item.link}` })); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); item.author = content(".article-content__authors-name").first().text().trim(); item.pubDate = timezone(parseDate(content("meta[property=\"article:published_time\"]").attr("content")), 8); item.description = content(".article-content__focus").html() + content(".article-content__editor").find("p, figure, h2, .video-container").toArray().map((e) => content.html(e)).join(""); item.category = content("meta[name=\"news_keywords\"]").attr("content").split(","); return item; }))); return { title: `轉角國際 udn Global - ${tag}`, link: currentUrl, item: items }; } //#endregion export { route };