feat: support ICEBORNE for /monsterhunter/update
This commit is contained in:
parent
6586f09907
commit
aea94fa664
|
|
@ -2,33 +2,67 @@ const got = require('@/utils/got');
|
|||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'http://game.capcom.com/world/cn/infomation.html';
|
||||
|
||||
const response = await got({
|
||||
const url1 = 'http://game.capcom.com/world/cn/infomation.html';
|
||||
const response1 = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
url: url1,
|
||||
});
|
||||
let $ = cheerio.load(response1.data);
|
||||
const result1 = $('.version')
|
||||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('h3').text(),
|
||||
description: item.children('div').html(),
|
||||
link: url1,
|
||||
author: 'MONSTER HUNTER: WORLD',
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const url2 = 'https://www.monsterhunter.com/update/mhw/cn/';
|
||||
const response2 = await got({
|
||||
method: 'get',
|
||||
url: url2,
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
$ = cheerio.load(response2.data);
|
||||
let result2 = $('.btn a')
|
||||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.text').text(),
|
||||
pubDate: new Date(item.find('.date').text()).toUTCString(),
|
||||
link: url2 + item.attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('.version');
|
||||
result2 = await Promise.all(
|
||||
result2.map(async (item) =>
|
||||
Promise.resolve(
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got.get(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
return {
|
||||
title:
|
||||
$('.page-ttl')
|
||||
.text()
|
||||
.trim() || item.title,
|
||||
description: $('#contents').html(),
|
||||
link: item.link,
|
||||
pubDate: item.pubDate,
|
||||
author: 'MONSTER HUNTER WORLD: ICEBORNE',
|
||||
};
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '怪物猎人更新情报',
|
||||
link: url,
|
||||
item:
|
||||
list &&
|
||||
list
|
||||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('h3').text(),
|
||||
description: item.children('div').html(),
|
||||
link: url,
|
||||
guid: item.find('h3').text(),
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
link: url2,
|
||||
item: result2.concat(result1),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue