rsshub
Version:
Make RSS Great Again!
96 lines (94 loc) • 3.29 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import { t as config } from "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.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 dayjs from "dayjs";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore.js";
import { load } from "cheerio";
//#region lib/routes/openai/chatgpt.ts
dayjs.extend(isSameOrBefore);
const route = {
path: "/chatgpt/release-notes",
categories: ["program-update"],
example: "/openai/chatgpt/release-notes",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "ChatGPT - Release Notes",
maintainers: [],
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 returns = [];
const $ = load((await got_default({
method: "get",
url: articleUrl
})).data);
const page = JSON.parse($("script#__NEXT_DATA__").text());
const feedTitle = page.props.pageProps.articleContent.title;
const feedDesc = page.props.pageProps.articleContent.description;
const authorName = page.props.pageProps.articleContent.author.name;
const $blocks = page.props.pageProps.articleContent.blocks;
const anchorDay = dayjs();
let heading = null, articleObj = {};
let year = anchorDay.year();
let prevMonth = -1;
for (const block of $blocks) {
const text = (block.text || "").trim();
if (!text) continue;
if (block.type === "subheading") {
if (heading !== null) {
articleObj.description = articleObj.description.trim().replaceAll("\n", "<br/>");
returns.push(articleObj);
articleObj = {};
}
heading = text;
articleObj.title = heading;
articleObj.author = authorName;
articleObj.category = "ChatGPT";
articleObj.link = articleUrl + "#" + block.idAttribute;
articleObj.guid = articleUrl + "#" + block.idAttribute;
articleObj.description = "";
const matchesPubDate = heading.match(/\((\w+\s+\d{1,2})\)$/);
if (matchesPubDate !== null) {
const curMonth = 1 + "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(",").indexOf(matchesPubDate[1].slice(0, 3));
if (prevMonth !== -1 && prevMonth < curMonth) year--;
prevMonth = curMonth;
const pubDay = dayjs(`${matchesPubDate[1]}, ${year}`, ["MMMM D, YYYY", "MMM D, YYYY"], "en", true);
articleObj.pubDate = dayjs(pubDay.toISOString().replace(/\.\d{3}Z$/, "-08:00"));
const linkAnchor = pubDay.format("YYYY_MM_DD");
articleObj.guid = articleUrl + "#" + linkAnchor;
}
} else articleObj.description += block.text.trim() + "\n\n";
}
if (heading !== null) {
articleObj.description = articleObj.description.trim().replaceAll("\n", "<br/>");
returns.push(articleObj);
}
return {
feedTitle,
feedDesc,
items: returns
};
}, config.cache.routeExpire, false);
return {
title: cacheIn.feedTitle,
description: cacheIn.feedDesc,
link: articleUrl,
item: cacheIn.items
};
}
//#endregion
export { route };