diff --git a/lib/v2/onet/maintainer.js b/lib/v2/onet/maintainer.js new file mode 100644 index 000000000..8a1875e34 --- /dev/null +++ b/lib/v2/onet/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['Vegann'], +}; diff --git a/lib/v2/onet/news.js b/lib/v2/onet/news.js new file mode 100644 index 000000000..225e146a7 --- /dev/null +++ b/lib/v2/onet/news.js @@ -0,0 +1,56 @@ +const parser = require('@/utils/rss-parser'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); +const { parseArticleContent, parseMainImage } = require('./utils'); + +module.exports = async (ctx) => { + const rssUrl = 'https://wiadomosci.onet.pl/.feed'; + const feed = await parser.parseURL(rssUrl); + const items = await Promise.all( + feed.items.map(async (item) => { + const { description, author, category } = await ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link, { + headers: { + referer: 'https://www.onet.pl/', // for some reason onet.pl will redirect to the main page if referer is not set + }, + }); + + const $ = cheerio.load(response); + const content = parseArticleContent($); + + const mainImage = parseMainImage($); + + const description = art(path.join(__dirname, 'templates/article.art'), { + mainImage, + lead: $('#lead').text()?.trim(), + content: content.html()?.trim(), + }); + + const author = $('.authorNameWrapper span[itemprop="name"]').text()?.trim(); + const category = $('span.relatedTopic').text()?.trim(); + + return { description, author, category }; + }); + return { + title: item.title, + link: item.link, + description, + author, + category, + pubDate: parseDate(item.pubDate), + guid: item.id, + }; + }) + ); + ctx.state.data = { + title: feed.title, + link: feed.link, + description: feed.title, + item: items, + language: 'pl', + image: 'https://ocdn.eu/wiadomosciucs/static/logo2017/onet2017big_dark.png', + }; +}; diff --git a/lib/v2/onet/radar.js b/lib/v2/onet/radar.js new file mode 100644 index 000000000..f29d2f6b0 --- /dev/null +++ b/lib/v2/onet/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'onet.pl': { + _name: 'Onet', + wiadomosci: [ + { + title: 'News', + docs: 'https://docs.rsshub.app/routes/new-media#onet', + source: '/', + target: '/onet/news', + }, + ], + }, +}; diff --git a/lib/v2/onet/router.js b/lib/v2/onet/router.js new file mode 100644 index 000000000..630036b8e --- /dev/null +++ b/lib/v2/onet/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news', require('./news')); +}; diff --git a/lib/v2/onet/templates/article.art b/lib/v2/onet/templates/article.art new file mode 100644 index 000000000..36ed5db53 --- /dev/null +++ b/lib/v2/onet/templates/article.art @@ -0,0 +1,5 @@ +{{if lead }} +
{{ lead }}
+{{/if}} +{{@ mainImage }} +{{@ content }} diff --git a/lib/v2/onet/templates/image.art b/lib/v2/onet/templates/image.art new file mode 100644 index 000000000..a4a8c8724 --- /dev/null +++ b/lib/v2/onet/templates/image.art @@ -0,0 +1,9 @@ +