rsshub
Version:
Make RSS Great Again!
136 lines (134 loc) • 5.13 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/apple/security-releases.ts
init_esm_shims();
const handler = async (ctx) => {
const { language = "en-us" } = ctx.req.param();
const limit = Number.parseInt(ctx.req.query("limit") ?? "30", 10);
const baseUrl = "https://support.apple.com";
const targetUrl = new URL(`${language}/100100`, baseUrl).href;
const $ = load(await ofetch_default(targetUrl));
const $trEls = $("table.gb-table tbody tr");
const headers = $trEls.find("th").toArray().map((el) => $(el).text());
let items = [];
items = $trEls.slice(1, limit).toArray().map((el) => {
const $el = $(el);
const titleEl = $el.find("td").first();
const title = titleEl.contents().first().text();
const description = art(path.join(__dirname, "templates/security-releases-f17de8c3.art"), {
headers,
infos: $el.find("td").toArray().map((el$1) => $(el$1).html() ?? "")
});
const pubDateStr = $el.find("td").last().text();
const linkUrl = titleEl.find("a.gb-anchor").attr("href");
const authors = $el.find("meta[property=\"og:site_name\"]").attr("content");
const upDatedStr = pubDateStr;
return {
title,
description,
pubDate: pubDateStr ? parseDate(pubDateStr, ["DD MMM YYYY", "YYYY 年 MM 月 DD 日"]) : void 0,
link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0,
author: authors,
content: {
html: description,
text: description
},
updated: upDatedStr ? parseDate(upDatedStr, ["DD MMM YYYY", "YYYY 年 MM 月 DD 日"]) : void 0,
language
};
});
items = await Promise.all(items.map((item) => {
if (!item.link) return item;
return cache_default.tryGet(item.link, async () => {
const detailResponse = await ofetch_default(item.link);
const $$ = load(detailResponse);
const title = item.title ?? $$("h1.gb-header").text();
$$("h1.gb-header").remove();
const description = item.description + art(path.join(__dirname, "templates/security-releases-f17de8c3.art"), { description: $$("div#sections").html() });
const pubDateStr = detailResponse.match(/publish_date:\s"(\d{8})",/, "")?.[1];
const authors = $$("meta[property=\"og:site_name\"]").attr("content");
const upDatedStr = $$(".time").text() || pubDateStr;
const processedItem = {
title,
description,
pubDate: pubDateStr ? parseDate(pubDateStr, "MMDDYYYY") : item.pubDate,
author: authors,
content: {
html: description,
text: description
},
updated: upDatedStr ? parseDate(upDatedStr, "MMDDYYYY") : item.updated,
language
};
return {
...item,
...processedItem
};
});
}));
return {
title: $("title").text(),
description: $("meta[property=\"og:description\"]").attr("content"),
link: targetUrl,
item: items,
allowEmpty: true,
author: $("meta[property=\"og:site_name\"]").attr("content"),
language,
id: targetUrl
};
};
const route = {
path: "/security-releases/:language?",
name: "Security releases",
url: "support.apple.com",
maintainers: ["nczitzk"],
handler,
example: "/apple/security-releases",
parameters: { language: { description: "Language, `en-us` by default" } },
description: `::: tip
To subscribe to [Apple security releases](https://support.apple.com/en-us/100100), where the source URL is \`https://support.apple.com/en-us/100100\`, extract the certain parts from this URL to be used as parameters, resulting in the route as [\`/apple/security-releases/en-us\`](https://rsshub.app/apple/security-releases/en-us).
:::
`,
categories: ["program-update"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["support.apple.com/:language/100100"],
target: (params) => {
const language = params.language;
return `/apple/security-releases${language ? `/${language}` : ""}`;
}
}],
view: ViewType.Articles,
zh: {
path: "/security-releases/:language?",
name: "安全性发布",
url: "support.apple.com",
maintainers: ["nczitzk"],
handler,
example: "/apple/security-releases",
parameters: { language: { description: "语言,默认为 `en-us`,可在对应页 URL 中找到" } },
description: `::: tip
若订阅 [Apple 安全性发布](https://support.apple.com/zh-cn/100100),网址为 \`https://support.apple.com/zh-cn/100100\`,请截取 \`https://support.apple.com/\` 到末尾 \`/100100\` 的部分 \`zh-cn\` 作为 \`language\` 参数填入,此时目标路由为 [\`/apple/security-releases/zh-cn\`](https://rsshub.app/apple/security-releases/zh-cn)。
:::
`
}
};
//#endregion
export { handler, route };