UNPKG

rsshub

Version:
67 lines (65 loc) 2.06 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import { t as ViewType } from "./types-gOySfSXJ.mjs"; import "./logger-C4avouvV.mjs"; import "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import "./helpers-Bo4JQYdN.mjs"; import { t as got_default } from "./got-CO-ndVl2.mjs"; import { t as timezone } from "./timezone-CA9Huotp.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 };