rsshub
Version:
Make RSS Great Again!
67 lines (65 loc) • 2.06 kB
JavaScript
import "./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 "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.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 { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { load } from "cheerio";
//#region lib/routes/nasa/apod.ts
const route = {
path: "/apod",
categories: ["picture"],
view: ViewType.Pictures,
example: "/nasa/apod",
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["apod.nasa.govundefined"] }],
name: "Astronomy Picture of the Day",
maintainers: ["nczitzk", "williamgateszhao"],
handler,
url: "apod.nasa.govundefined"
};
async function handler(ctx) {
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 10;
const rootUrl = "https://apod.nasa.gov/apod/archivepix.html";
const $ = load((await got_default({
method: "get",
url: rootUrl
})).data);
const list = $("body > b > a").slice(0, limit).toArray().map((el) => ({
title: $(el).text(),
link: `https://apod.nasa.gov/apod/${$(el).attr("href")}`
}));
return {
title: "NASA Astronomy Picture of the Day",
link: rootUrl,
item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await got_default({
method: "get",
url: item.link
})).data);
const description = `<img src="${content("img").attr("src")}"> <br> ${content("body > center").eq(1).html()} <br> ${content("body > p").eq(0).html()}`;
const pubDate = timezone(parseDate(item.link.slice(-11, -5), "YYMMDD"), -5);
return {
title: item.title,
description,
pubDate,
link: item.link
};
})))
};
}
//#endregion
export { route };