UNPKG

rsshub

Version:
67 lines (65 loc) 2.2 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 "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/fisher-spb/news.ts init_esm_shims(); const route = { path: "/news", categories: ["other"], example: "/fisher-spb/news", parameters: {}, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["fisher.spb.ru/news"] }], name: "News", maintainers: ["denis-ya"], handler, url: "fisher.spb.ru/news" }; async function handler() { const renderVideo = (link) => art(path.join(__dirname, "templates/video-044c4004.art"), { link }); const renderImage = (href) => art(path.join(__dirname, "templates/image-1ae3fe80.art"), { href }); const rootUrl = "https://fisher.spb.ru/news/"; const $ = load((await got_default({ method: "get", url: rootUrl, responseType: "buffer" })).data); const descBuilder = (element) => { const content = load(`<p>${$(".news-message-text", element).html()}</p>`).root(); $(".news-message-media a", element).each((_, elem) => { if ($(elem).hasClass("news-message-youtube")) content.append(renderVideo($(elem).attr("data-youtube"))); else content.append(renderImage($(elem).attr("href"))); }); return content; }; const items = $(".news-message").toArray().map((elem) => ({ pubDate: parseDate($(".news-message-date", elem).text().trim(), "DD.MM.YYYY HH:mm"), title: $(".news-message-location", elem).text().trim(), description: descBuilder(elem).html(), author: $(".news-message-user", elem).text().trim(), guid: $(elem).attr("id"), link: rootUrl + $(".news-message-comments-number > a", elem).attr("href") })); return { title: $("head > title").text().trim(), link: rootUrl, item: items }; } //#endregion export { route };