diff --git a/docs/en/other.md b/docs/en/other.md index 18067718bb25a4..d97c7c5d1f5d70 100644 --- a/docs/en/other.md +++ b/docs/en/other.md @@ -220,3 +220,9 @@ Type | all | rec | + +## Fisher Spb + +### News + + diff --git a/lib/v2/fisher-spb/maintainer.js b/lib/v2/fisher-spb/maintainer.js new file mode 100644 index 00000000000000..78023c3d09c310 --- /dev/null +++ b/lib/v2/fisher-spb/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news': ['denis-ya'], +}; diff --git a/lib/v2/fisher-spb/news.js b/lib/v2/fisher-spb/news.js new file mode 100644 index 00000000000000..8bd04c42d7b167 --- /dev/null +++ b/lib/v2/fisher-spb/news.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + + const renderVideo = (link) => art(path.join(__dirname, './templates/video.art'), { link }); + const renderImage = (href) => art(path.join(__dirname, './templates/image.art'), { href }); + + const rootUrl = 'https://fisher.spb.ru/news/'; + const response = await got({ + method: 'get', + url: rootUrl, + responseType: 'buffer' + }); + + const $ = cheerio.load(iconv.decode(response.data, 'windows-1251')); + + const descBuilder = (element) => { + const content = cheerio.load(`

${$('.news-message-text', element).html()}

`).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') + .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') + })) + .get(); + + ctx.state.data = { + title: $('head > title').text().trim(), + link: rootUrl, + item: items + }; +}; diff --git a/lib/v2/fisher-spb/radar.js b/lib/v2/fisher-spb/radar.js new file mode 100644 index 00000000000000..581c10efd1b788 --- /dev/null +++ b/lib/v2/fisher-spb/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'fisher.spb.ru': { + _name: 'fisher spb', + '.': [ + { + title: 'news', + docs: 'https://docs.rsshub.app/en/other.html#fisher-spb', + source: ['/news'], + target: '/fisher-spb/news', + }, + ], + }, +}; diff --git a/lib/v2/fisher-spb/router.js b/lib/v2/fisher-spb/router.js new file mode 100644 index 00000000000000..69a5972f6a8112 --- /dev/null +++ b/lib/v2/fisher-spb/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news', require('./news')); +}; diff --git a/lib/v2/fisher-spb/templates/image.art b/lib/v2/fisher-spb/templates/image.art new file mode 100644 index 00000000000000..de65644dbd264f --- /dev/null +++ b/lib/v2/fisher-spb/templates/image.art @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/lib/v2/fisher-spb/templates/video.art b/lib/v2/fisher-spb/templates/video.art new file mode 100644 index 00000000000000..1a6ed09779a861 --- /dev/null +++ b/lib/v2/fisher-spb/templates/video.art @@ -0,0 +1 @@ +
\ No newline at end of file