feat: 任天堂香港首页资讯 / 任天堂直面会日程 (#2143)

* fix: spelling error in docs

* feat: Nintendo HK news & Nintendo Direct

* format for nintendo source
This commit is contained in:
AaronLiu
2019-05-16 11:21:39 +08:00
committed by DIYgod
parent 770a094414
commit 80438731a3
5 changed files with 103 additions and 1 deletions
+9 -1
View File
@@ -42,7 +42,15 @@ pageClass: routes
### eShop 新发售游戏
<Route author="Aaron Liu" example="/nintendo/eshop/hk" path="/nintendo/eshop/:region" :paramsDesc="['地区标识,可为`hk`(港服),`jp`(日服),`us`(美服)']"/>
<Route author="HFO4" example="/nintendo/eshop/hk" path="/nintendo/eshop/:region" :paramsDesc="['地区标识,可为`hk`(港服),`jp`(日服),`us`(美服)']"/>
### 首页资讯(香港)
<Route author="HFO4" example="/nintendo/news" path="/nintendo/news"/>
### 直面会
<Route author="HFO4" example="/nintendo/direct" path="/nintendo/direct"/>
## PlayStation Store
+2
View File
@@ -1231,6 +1231,8 @@ router.get('/ps/list/:gridName', require('./routes/ps/list'));
router.get('/nintendo/eshop/jp', require('./routes/nintendo/eshop_jp'));
router.get('/nintendo/eshop/hk', require('./routes/nintendo/eshop_hk'));
router.get('/nintendo/eshop/us', require('./routes/nintendo/eshop_us'));
router.get('/nintendo/news', require('./routes/nintendo/news'));
router.get('/nintendo/direct', require('./routes/nintendo/direct'));
// 世界卫生组织
router.get('/who/news-room/:type', require('./routes/who/news-room'));
+40
View File
@@ -0,0 +1,40 @@
const axios = require('@/utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await axios({
method: 'get',
url: 'https://www.nintendo.com/nintendo-direct/archive/',
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.news-tiles li')
.get()
.slice(0, 9);
const result = list.map((item) => {
const $ = cheerio.load(item);
return {
title: $('.b7').html(),
cover: $('img ')
.attr('src')
.replace('../', 'https://www.nintendo.com/nintendo-direct/'),
des: $('p').html(),
url: $('a')
.attr('href')
.replace('../', 'https://www.nintendo.com/nintendo-direct/'),
};
});
ctx.state.data = {
title: `Nintendo Direct (任天堂直面会)`,
link: `https://www.nintendo.com/nintendo-direct/archive/`,
description: `最新的任天堂直面会日程信息`,
item: result.map((item) => ({
title: item.title,
description: `<img referrerpolicy="no-referrer" src="${item.cover}" /><br>${item.des}`,
link: item.url,
})),
};
};
+25
View File
@@ -0,0 +1,25 @@
const axios = require('@/utils/axios');
const util = require('./utils');
module.exports = async (ctx) => {
const response = await axios({
method: 'get',
url: `https://www.nintendo.com.hk/data/json/topics.json`,
});
const data = response.data.filter((val) => val.only_for !== 'tw' && val.url.startsWith('/topics/article/')).slice(0, 9);
// 获取新闻正文
const result = await util.ProcessNews(data, ctx.cache);
ctx.state.data = {
title: `Nintendo (香港) 主页资讯`,
link: `https://www.nintendo.com.hk/topics/index.html`,
description: `Nintendo香港有限公司官网刊登的资讯`,
item: result.map((item) => ({
title: item.title,
description: item.content,
link: `https://www.nintendo.com.hk${item.url}`,
pubDate: item.data,
})),
};
};
+27
View File
@@ -15,6 +15,24 @@ async function load(link) {
return { content: description };
}
async function loadNews(link) {
const response = await axios({
method: 'get',
url: link,
});
const data = response.data;
const $ = cheerio.load(data);
let description = $('.detail-body-container').html();
const date = $('.topics-articleHead__date').html();
description = description.replace(new RegExp('src="/topics/', 'g'), ' referrerpolicy="no-referrer" src="https://www.nintendo.com.hk/topics/');
return {
content: description,
date: new Date(date).toUTCString(),
};
}
const ProcessItem = async (list, caches) =>
await Promise.all(
list.map(async (item) => {
@@ -23,6 +41,15 @@ const ProcessItem = async (list, caches) =>
})
);
const ProcessNews = async (list, caches) =>
await Promise.all(
list.map(async (item) => {
const other = await caches.tryGet(item.link, async () => await loadNews('https://www.nintendo.com.hk' + item.url));
return Promise.resolve(Object.assign({}, item, other));
})
);
module.exports = {
ProcessItem,
ProcessNews,
};