UNPKG

rsshub

Version:
89 lines (88 loc) 3.57 kB
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs"; import "./types-DNj6Etbg.mjs"; import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as parser } from "./rss-parser-CmTb9lkc.mjs"; import { load } from "cheerio"; //#region lib/routes/apple/newsroom.ts const rootUrl = `https://www.apple.com.cn/newsroom/`; const feedUrl = `${rootUrl}rss-feed.rss`; const defaultLimit = 20; const articleCleanupSelector = ".scrollfade, .article-header, .featured-header, .paddlenav, .articleshare, .nr-article-share, .docsanddownloads, .presscontacts, .sharesheet, .nr-accordion, .sosumi"; const articleElementCleanupSelector = "style, picture source, button, aside, [download]"; const extractArticleDescription = ($) => { const article = $(".article"); if (!article.length) return; $(articleCleanupSelector, article).remove(); $(articleElementCleanupSelector, article).remove(); article.find("[style]").removeAttr("style"); article.find("sup").remove(); return article.html() ?? void 0; }; const fetchArticle = (item) => cache_default.tryGet(item.link, async () => { const $ = load(await rofetch(item.link)); const category = $(".category-eyebrow__category").first().text(); const fallbackDate = $(".category-eyebrow__date").first().text(); const description = extractArticleDescription($); const ogTitle = $("meta[property=\"og:title\"]").attr("content"); const ogImage = $("meta[property=\"og:image\"]").attr("content"); const pubDate = item.isoDate ?? item.pubDate; return { title: ogTitle ?? item.title ?? item.link, link: item.link, description: description ?? item.content ?? item.contentSnippet, pubDate: pubDate ? parseDate(pubDate) : fallbackDate ? parseDate(fallbackDate, "YYYY 年 M 月 D 日") : void 0, author: item.author ?? "Apple Newsroom", category: category ? [category] : item.categories, image: ogImage ?? item.enclosure?.url }; }); async function handler(ctx) { const limit = Number(ctx.req.query("limit")) || defaultLimit; const feedResponse = await rofetch(feedUrl, { parseResponse: (text) => text }); const feed = await parser.parseString(feedResponse); const items = await Promise.all(feed.items.slice(0, limit).filter((item) => Boolean(item.link)).map((item) => fetchArticle(item))); return { title: "Apple Newsroom (中国大陆)", link: rootUrl, feedLink: feedUrl, description: "Apple 新闻中心是 Apple 新闻的来源。阅读新闻稿、获取最新消息、观看视频和下载图片。", item: items, language: "zh-CN" }; } const route = { path: "/newsroom", name: "Newsroom (中国大陆)", url: "www.apple.com.cn/newsroom", maintainers: ["LinxHex"], example: "/apple/newsroom", description: "The official source for news about Apple, from Apple. Read press releases, get updates, watch video and download images.", categories: ["new-media"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.apple.com.cn/newsroom", "www.apple.com.cn/newsroom/:year/:month/:slug"], target: "/newsroom" }], view: 0, zh: { path: "/newsroom", name: "新闻中心(中国大陆)", url: "www.apple.com.cn/newsroom", maintainers: ["LinxHex"], example: "/apple/newsroom", description: "Apple 新闻中心是 Apple 新闻的来源。阅读新闻稿、获取最新消息、观看视频和下载图片。", handler }, handler }; //#endregion export { route };