forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add fisher spb news (DIYgod#8343)
* feat(route): add fisher spb news * Apply suggestions from code review Co-authored-by: Tony <[email protected]> * templates art for html render Co-authored-by: Tony <[email protected]>
- Loading branch information
Showing
7 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/news': ['denis-ya'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(`<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') | ||
.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 | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function (router) { | ||
router.get('/news', require('./news')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<img style="max-width: 650px; height: auto; object-fit: contain; flex: 0 0 auto;" src="{{ href }}"></img><br/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<iframe type="text/html" width="640" height="360" src="https://youtube.com/embed/{{ link }}" frameborder="0" allowfullscreen></iframe><br/> |