UNPKG

rsshub

Version:
117 lines (114 loc) 3.73 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 rss_parser_default } from "./rss-parser-Dtop7M8f.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/onet/utils.ts init_esm_shims(); const parseMainImage = ($) => { const mainImage = $("figure.mainPhoto"); const img = mainImage.find("img"); const author = mainImage.find("span.copyright"); const caption = mainImage.find("span.imageDescription"); return art(path.join(__dirname, "templates/image-230aff8e.art"), { url: img.attr("src"), alt: img.attr("alt")?.trim(), author: author.text()?.trim(), caption: caption.text()?.trim() }); }; const parseArticleContent = ($) => { const content = $("[itemprop=\"articleBody\"]"); $("*").contents().filter(function() { return this.nodeType === 8; }).remove(); content.find("aside").remove(); content.find(".videoPlayerContainer").remove(); content.find(".pulsevideo").remove(); content.find(".adsContainer").remove(); content.find(".placeholder").remove(); content.find(".contentPremium").removeAttr("style"); content.find("div.image").each((i, el) => { const img = $(el).find("img"); const author = $(el).find("span.author"); const caption = $(el).find("span.caption"); const html = art(path.join(__dirname, "templates/image-230aff8e.art"), { url: img.attr("src"), alt: img.attr("alt")?.trim(), caption: caption.text()?.trim(), author: author.text()?.trim() }); $(el).replaceWith(html); }); return content; }; //#endregion //#region lib/routes/onet/news.ts init_esm_shims(); const route = { path: "/news", categories: ["new-media"], example: "/onet/news", parameters: {}, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["wiadomosci.onet.pl/"] }], name: "News", maintainers: ["Vegann"], handler, url: "wiadomosci.onet.pl/", description: `This route provides a better reading experience (full text articles) over the official one for \`https://wiadomosci.onet.pl\`.` }; async function handler() { const feed = await rss_parser_default.parseURL("https://wiadomosci.onet.pl/.feed"); const items = await Promise.all(feed.items.map(async (item) => { const { description, author, category } = await cache_default.tryGet(item.link, async () => { const { data: response } = await got_default(item.link, { headers: { referer: "https://www.onet.pl/" } }); const $ = load(response); const content = parseArticleContent($); const mainImage = parseMainImage($); return { description: art(path.join(__dirname, "templates/article-fc2b2fbf.art"), { mainImage, lead: $("#lead").text()?.trim(), content: content.html()?.trim() }), author: $(".authorNameWrapper span[itemprop=\"name\"]").text()?.trim(), category: $("span.relatedTopic").text()?.trim() }; }); return { title: item.title, link: item.link, description, author, category, pubDate: parseDate(item.pubDate), guid: item.id }; })); return { title: feed.title, link: feed.link, description: feed.title, item: items, language: "pl", image: "https://ocdn.eu/wiadomosciucs/static/logo2017/onet2017big_dark.png" }; } //#endregion export { route };