UNPKG

rsshub

Version:
65 lines (63 loc) 2.4 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.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 { o as journalMap, t as baseUrl } from "./utils-9e_EwON4.mjs"; import { load } from "cheerio"; import { CookieJar } from "tough-cookie"; //#region lib/routes/nature/cover.ts const route = { path: "/cover", categories: ["journal"], example: "/nature/cover", parameters: {}, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["nature.com/"] }], name: "Cover Story", maintainers: ["y9c", "pseudoyu"], handler, url: "nature.com/", description: `Subscribe to the cover images of the Nature journals, and get the latest publication updates in time.` }; async function handler() { const cookieJar = new CookieJar(); await got_default("https://www.nature.com", { cookieJar }); const journals = journalMap.items.filter((j) => j.id).map((j) => ({ ...j, link: `${baseUrl}/${j.title}/current-issue` })); return { title: "Nature Covers Story", description: "Find out the cover story of some Nature journals.", link: baseUrl, item: await Promise.all(journals.map((journal) => cache_default.tryGet(journal.link, async () => { const { id, name, link } = journal; const response = await got_default(link, { cookieJar }); const $ = load(response.data); const { volume, issue } = $("meta[property=\"og:url\"]").attr("content")?.match(/volumes\/(?<volume>\d+)\/issues\/(?<issue>\d+)/)?.groups ?? {}; const contents = `<div align="center"><img src="${`https://media.springernature.com/full/springer-static/cover-hires/journal/${id}/${volume}/${issue}?as=webp`}" alt="Volume ${volume} Issue ${issue}"></div>`; const date = $("title").text().split(",")[1].trim(); const issueDescription = $("div[data-test=issue-description]").html() ?? ""; return { title: `${name} | Volume ${volume} Issue ${issue}`, description: contents + issueDescription, link: response.url, pubDate: parseDate(date, "MMMM YYYY") }; }))) }; } //#endregion export { route };