feat: 添加 Nintendo Switch 本体更新情报 (#3469)

This commit is contained in:
hoilc
2019-11-22 18:15:58 +08:00
committed by DIYgod
parent adf59c4974
commit d4846e52e5
3 changed files with 45 additions and 0 deletions

View File

@@ -100,6 +100,10 @@ pageClass: routes
<Route author="HFO4" example="/nintendo/direct" path="/nintendo/direct"/>
### Switch 本体更新情报(日本)
<Route author="hoilc" example="/nintendo/system-update" path="/nintendo/system-update"/>
## PlayStation
### PlayStation Store 游戏列表

View File

@@ -1364,6 +1364,7 @@ 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('/nintendo/system-update', require('./routes/nintendo/system-update'));
// 世界卫生组织
router.get('/who/news-room/:type', require('./routes/who/news-room'));

View File

@@ -0,0 +1,40 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'https://www.nintendo.co.jp/support/switch/system_update/index.html';
const response = await got.get(url);
const $ = cheerio.load(response.data);
const list = $('#latest > .c-heading-lv3')
.toArray()
.slice(1);
ctx.state.data = {
title: 'Nintendo Switch 本体更新情報',
link: url,
item: list.map((update) => {
update = $(update);
const heading = update.text();
const matched_date = /(\d+)年(\d+)月(\d+)日/.exec(heading);
const update_info = update.nextUntil('.c-heading-lv3');
const update_infos = update_info
.map(function() {
return $(this).html();
})
.get()
.join('\n');
const matched_version = /(\d\.)+\d/.exec(heading);
return {
title: heading,
author: 'Nintendo',
description: update_infos,
link: url,
guid: `${url}#${matched_version[0]}`,
pubDate: new Date(parseInt(matched_date[1]), parseInt(matched_date[2]) - 1, parseInt(matched_date[3])),
};
}),
};
};