rsshub
Version:
Make RSS Great Again!
53 lines (52 loc) • 1.86 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { load } from "cheerio";
//#region lib/routes/reactnativenewsletter/index.ts
const route = {
path: "/",
categories: ["programming"],
example: "/reactnativenewsletter",
radar: [{
source: ["reactnativenewsletter.com/past-issues", "reactnativenewsletter.com/"],
target: ""
}],
name: "Past Issues",
maintainers: ["yiuyiu"],
handler,
url: "reactnativenewsletter.com/past-issues"
};
async function handler(ctx) {
const baseUrl = "https://reactnativenewsletter.com";
const link = `${baseUrl}/past-issues`;
const $ = load(await rofetch(link));
const archiveUrls = [...new Set($(".campaign__list__year script[src*=\"generate-js\"]").toArray().map((script) => new URL($(script).attr("src"), baseUrl).href))];
const list = (await Promise.all(archiveUrls.map((url) => rofetch(url)))).flatMap((archive) => {
const $$ = load(JSON.parse(archive.match(/document\.write\((".*")\);/s)[1]));
return $$(".campaign").toArray().map((item) => {
const $item = $$(item);
const a = $item.find("a");
return {
title: a.text(),
link: a.attr("href"),
pubDate: parseDate($item.text().split(" - ", 1)[0], "MM/DD/YYYY")
};
});
}).toSorted((a, b) => b.pubDate.valueOf() - a.pubDate.valueOf()).slice(0, ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 20);
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const $ = load(await rofetch(item.link));
return {
...item,
description: $("#templateBody").html()
};
})));
return {
title: $("head title").text(),
description: $("meta[name=\"description\"]").attr("content"),
link,
language: "en",
item: items
};
}
//#endregion
export { route };