UNPKG

rsshub

Version:
105 lines (100 loc) 3.64 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.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 art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/dn/news.ts init_esm_shims(); const route = { path: "/:language/news/:category?", categories: ["new-media"], example: "/dn/en-us/news", parameters: { language: "Language, see below", category: "Category, see below, The Latest by default" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "News", maintainers: ["nczitzk"], handler, description: `#### Language | English | 中文 | | ------- | ----- | | en-us | zh-cn | #### Category | English Category | 中文分类 | Category id | | -------------------- | -------- | ----------- | | The Latest | 最新 | | | Industry Information | 行业资讯 | category-1 | | Knowledge | 域名知识 | category-2 | | Investment | 域名投资 | category-3 |` }; async function handler(ctx) { const { language, category = "" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 10; const rootUrl = "https://dn.com"; const currentUrl = new URL(`/${language}/news/${category}`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); let items = $("a.list-item").slice(0, limit).toArray().map((item) => { item = $(item); const image = item.find("div.img img"); return { title: item.find("h2.ellipse2").text(), link: new URL(item.prop("href"), rootUrl).href, description: art(path.join(__dirname, "templates/description-024a8505.art"), { image: image ? { src: image.prop("src"), alt: image.prop("alt") } : void 0, abstracts: item.find("p.abstract").html() }), category: item.find("span.cat").toArray().map((c) => $(c).text()), pubDate: timezone(parseDate(item.find("span.time").text()), 8) }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); item.title = content("h1.tit").text(); item.description = art(path.join(__dirname, "templates/description-024a8505.art"), { abstracts: content("div.abstract").html(), description: content("div.detail").html() }); item.author = content("span.author").text().replace(/(By|作者)\s/, ""); item.category = [...item.category, ...content("div.tags p a").toArray().map((c) => content(c).text())]; item.pubDate = timezone(parseDate(content("span.date").text()), 8); return item; }))); const title = $("a.logo img").prop("alt"); const icon = $("link[rel=\"icon\"]").prop("href"); return { item: items, title: `${title} - ${$("div.group a.active").text()}`, link: currentUrl, description: $("meta[name=\"description\"]").prop("content"), language: $("html").prop("lang"), image: new URL($("a.logo img").prop("src"), rootUrl).href, icon, logo: icon, subtitle: $("title").text(), author: title }; } //#endregion export { route };