UNPKG

rsshub

Version:
74 lines (73 loc) 2.09 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.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()); const date = match ? match[1] : o.attr("datetime"); return timezone(parseDate(date), 9); }; async function handler(ctx) { const { type } = ctx.req.param(); const cfg = config[type]; if (!cfg) throw new Error("Bad type"); const response = await rofetch(new URL(cfg.link, rootUrl).href); const $ = load(response); const list = $("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")) }; }); const items = await pMap(list, (item) => cache_default.tryGet(`emi-nitta${item.link}`, async () => { const detailUrl = new URL(item.link, rootUrl).href; const res = await rofetch(detailUrl); const content = load(res); 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 };