UNPKG

rsshub

Version:
70 lines (69 loc) 2 kB
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 { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; import pMap from "p-map"; //#region lib/routes/emi-nitta/home.ts const route = { path: "/:type", categories: ["other"], example: "/emi-nitta/updates", parameters: { type: "Type, `updates` or `news`" }, radar: [{ source: ["emi-nitta.net/updates"], target: "/updates" }, { source: ["emi-nitta.net/contents/news"], target: "/news" }], name: "Recent update / News", maintainers: ["luyuhuang"], handler }; const rootUrl = "https://emi-nitta.net"; const config = { updates: { link: "/updates", title: "Emi Nitta - Updates", description: "Recent update of Emi Nitta official website" }, news: { link: "/contents/news", title: "Emi Nitta - News", description: "News of Emi Nitta" } }; const getDate = (o) => { const match = /(\d{4}\.\d+\.\d+)/.exec(o.text()); return timezone(parseDate(match ? match[1] : o.attr("datetime")), 9); }; async function handler(ctx) { const { type } = ctx.req.param(); const cfg = config[type]; if (!cfg) throw new Error("Bad type"); const $ = load(await rofetch(new URL(cfg.link, rootUrl).href)); const items = await pMap($("article.details ul.list-unstyled li a").slice(0, 10).toArray().map((item) => { const $item = $(item); return { title: $item.find("div.title h3").text(), link: $item.attr("href"), pubDate: getDate($item.find("time")) }; }), (item) => cache_default.tryGet(`emi-nitta${item.link}`, async () => { const detailUrl = new URL(item.link, rootUrl).href; const content = load(await rofetch(detailUrl)); return { ...item, description: content("article.details div.body").html() }; }), { concurrency: 3 }); return { title: cfg.title, description: cfg.description, link: rootUrl, item: items }; } //#endregion export { route };