rsshub
Version:
Make RSS Great Again!
64 lines (63 loc) • 2.06 kB
JavaScript
import { t as rofetch } from "./ofetch-C3ts-Hud.mjs";
import { t as config } from "./config-CCmw1BNE.mjs";
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import dayjs from "dayjs";
import { load } from "cheerio";
//#region lib/routes/openai/chatgpt.ts
const route = {
path: "/chatgpt/release-notes",
categories: ["program-update"],
example: "/openai/chatgpt/release-notes",
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "ChatGPT - Release Notes",
maintainers: ["xbot"],
handler
};
async function handler() {
const articleUrl = "https://help.openai.com/en/articles/6825453-chatgpt-release-notes";
const cacheIn = await cache_default.tryGet(articleUrl, async () => {
const $ = load(await rofetch(articleUrl));
const articleContent = $(".article-content");
if (articleContent.length === 0) throw new Error("Failed to find article content.");
return {
feedTitle: $("h1").first().text(),
feedDesc: "ChatGPT Release Notes",
items: $("h1", articleContent).toArray().map((element) => {
const $h1 = $(element);
const text = $h1.text().trim();
const dateMatch = text.match(/(\w+\s+\d+[stndrh]*,\s+\d{4})/i);
let pubDate;
if (dateMatch) {
const dateStr = dateMatch[1];
const parsedDate = dayjs(dateStr, ["MMMM Do, YYYY", "MMMM D, YYYY"], "en");
if (parsedDate.isValid()) pubDate = parsedDate.toDate();
}
const $nextSiblings = $h1.nextUntil("h1");
const title = $nextSiblings.filter("h2").first().text().trim() || text;
const description = $nextSiblings.toArray().map((el) => $(el).prop("outerHTML")).join("");
return {
guid: `${articleUrl}#${pubDate ? pubDate.getTime() : text}`,
title,
link: articleUrl,
pubDate,
description
};
})
};
}, config.cache.routeExpire, false);
return {
title: cacheIn.feedTitle,
description: cacheIn.feedDesc,
link: articleUrl,
item: cacheIn.items
};
}
//#endregion
export { route };