feat: Add multiple language for engadget (#3800)

This commit is contained in:
KeiLongW
2020-01-31 17:30:19 +08:00
committed by GitHub
parent a16df7111a
commit 9e3c9bd216
4 changed files with 48 additions and 6 deletions

View File

@@ -51,7 +51,17 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more
### Chinese ### Chinese
<RouteEn author="JamesWDGu" example="/engadget-cn" path="/engadget-cn"/> <Route author="JamesWDGu" example="/engadget-cn" path="/engadget-cn"/>
### Multi-language
<Route author="JamesWDGu KeiLongW" example="/engadget/chinese" path="/engadget/:lang" :paramsDesc="['Language']">
| Traditional Chinese | Simplified Chinese | US | Japanese |
| ------------------- | ------------------ | --- | -------- |
| chinese | cn | us | japanese |
</Route>
## iDownloadBlog ## iDownloadBlog

View File

@@ -79,6 +79,16 @@ pageClass: routes
<Route author="JamesWDGu" example="/engadget-cn" path="/engadget-cn"/> <Route author="JamesWDGu" example="/engadget-cn" path="/engadget-cn"/>
### 多語言
<Route author="JamesWDGu KeiLongW" example="/engadget/chinese" path="/engadget/:lang" :paramsDesc="['語言']">
| 繁體中文 | 簡體中文 | US | 日文 |
| -------- | -------- | --- | -------- |
| chinese | cn | us | japanese |
</Route>
## iDownloadBlog ## iDownloadBlog
### blog ### blog

View File

@@ -1878,7 +1878,10 @@ router.get('/andyt/:view?', require('./routes/andyt/index'));
router.get('/pintu360/:type?', require('./routes/pintu360/index')); router.get('/pintu360/:type?', require('./routes/pintu360/index'));
// engadget中国版 // engadget中国版
router.get('/engadget-cn', require('./routes/engadget-cn/home')); router.get('/engadget-cn', require('./routes/engadget/home'));
// engadget
router.get('/engadget/:lang', require('./routes/engadget/home'));
// 吹牛部落 // 吹牛部落
router.get('/chuiniu/column/:id', require('./routes/chuiniu/column')); router.get('/chuiniu/column/:id', require('./routes/chuiniu/column'));

View File

@@ -3,11 +3,30 @@ const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser'); const parser = require('@/utils/rss-parser');
module.exports = async (ctx) => { module.exports = async (ctx) => {
const feed = await parser.parseURL('https://cn.engadget.com/rss.xml'); const lang = ctx.params.lang === 'us' ? 'www' : ctx.params.lang || 'cn';
const rssUrl = `https://${lang}.engadget.com/rss.xml`;
const feed = await parser.parseURL(rssUrl);
const ProcessFeed = (data) => { const ProcessFeed = (data) => {
const $ = cheerio.load(data); const $ = cheerio.load(data);
if (ctx.params.lang === 'us') {
$('div#engadget-article-footer').remove();
$('div#right-ads-rail').remove();
return $('div#page_body').html();
} else {
$('#post-slideshow figcaption').remove();
$('#post-slideshow div.pagination button').remove();
$('#post-slideshow img.scrollview-image-embedded').each((i, el) => {
$(el).attr('src', $(el).data('wf-src'));
});
$('#post-slideshow li.list-item-embedded')
.children()
.each((i, el) => {
$(el).insertAfter($(el).parent());
});
$('#post-slideshow li.list-item-embedded').remove();
return $('#post-center-col > div:nth-child(1)').html(); return $('#post-center-col > div:nth-child(1)').html();
}
}; };
const items = await Promise.all( const items = await Promise.all(
@@ -36,8 +55,8 @@ module.exports = async (ctx) => {
); );
ctx.state.data = { ctx.state.data = {
title: 'Engadget 中文版 全文', title: feed.title,
link: 'https://cn.engadget.com/', link: feed.link,
description: feed.description, description: feed.description,
item: items, item: items,
}; };