UNPKG

rsshub

Version:
133 lines (131 loc) 4.19 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import { t as ViewType } from "./types-D84BRIt4.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/asiafruitchina/news.ts init_esm_shims(); const handler = async (ctx) => { const limit = Number.parseInt(ctx.req.query("limit") ?? "30", 10); const baseUrl = "https://asiafruitchina.net"; const targetUrl = new URL("category/news", baseUrl).href; const $ = load(await ofetch_default(targetUrl)); const language = $("html").attr("lang") ?? "zh-CN"; let items = []; items = $("div.listBlocks ul li").slice(0, limit).toArray().map((el) => { const $el = $(el); const $aEl = $el.find("div.storyDetails h3 a"); const title$1 = $aEl.text(); const description = art(path.join(__dirname, "templates/description-16be3a2a.art"), { images: $el.find("a.image img").length > 0 ? $el.find("a.image img").toArray().map((imgEl) => { const $imgEl = $(imgEl); return { src: $imgEl.attr("src"), alt: $imgEl.attr("alt") }; }) : void 0 }); const pubDateStr = $el.find("span.date").text(); const linkUrl = $aEl.attr("href"); const image = $el.find("a.image img").attr("src"); const upDatedStr = pubDateStr; return { title: title$1, description, pubDate: pubDateStr ? parseDate(pubDateStr) : void 0, link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0, content: { html: description, text: description }, image, banner: image, updated: upDatedStr ? parseDate(upDatedStr) : void 0, language }; }); items = (await Promise.all(items.map((item) => { if (!item.link) return item; return cache_default.tryGet(item.link, async () => { const $$ = load(await ofetch_default(item.link)); const title$1 = $$("div.story_title h1").text(); const description = art(path.join(__dirname, "templates/description-16be3a2a.art"), { description: $$("div.storytext").html() }); const pubDateStr = $$("span.date").first().text().split(/:/).pop(); const categories = $$("meta[name=\"keywords\"]").attr("content")?.split(/,/).map((c) => c.trim()) ?? []; const authors = $$("span.author").first().text(); const upDatedStr = pubDateStr; let processedItem = { title: title$1, description, pubDate: pubDateStr ? parseDate(pubDateStr) : item.pubDate, category: categories, author: authors, content: { html: description, text: description }, updated: upDatedStr ? parseDate(upDatedStr) : item.updated, language }; const extraLinks = $$("div.extrasStory ul li").toArray().map((extraLinkEl) => { const $$extraLinkEl = $$(extraLinkEl); return { url: $$extraLinkEl.find("a").attr("href"), type: "related", content_html: $$extraLinkEl.html() }; }).filter((_) => true); if (extraLinks) processedItem = { ...processedItem, _extra: { links: extraLinks } }; return { ...item, ...processedItem }; }); }))).filter((_) => true); const title = $("title").text().trim(); return { title, description: $("meta[name=\"description\"]").attr("content"), link: targetUrl, item: items, allowEmpty: true, image: $("img.logo").attr("src"), author: title.split(/-/).pop(), language, id: targetUrl }; }; const route = { path: "/news", name: "行业资讯", url: "asiafruitchina.net", maintainers: ["nczitzk"], handler, example: "/asiafruitchina/news", parameters: void 0, description: void 0, categories: ["new-media"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["asiafruitchina.net/category/news"], target: "/asiafruitchina/news" }], view: ViewType.Articles }; //#endregion export { handler, route };