feat: add mhw news
This commit is contained in:
parent
cf59d5f249
commit
216e59686e
|
|
@ -199,6 +199,10 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
|
|||
|
||||
<Route author="DIYgod" example="/mhw/update" path="/mhw/update"/>
|
||||
|
||||
### 最新消息
|
||||
|
||||
<Route author="DIYgod" example="/mhw/news" path="/mhw/news"/>
|
||||
|
||||
## 旅法师营地
|
||||
|
||||
### 旅法师营地
|
||||
|
|
|
|||
|
|
@ -1437,8 +1437,9 @@ router.get('/dilbert/strip', require('./routes/dilbert/strip'));
|
|||
router.get('/yxdzqb/:type', require('./routes/yxdzqb'));
|
||||
|
||||
// 怪物猎人
|
||||
router.get('/monsterhunter/update', require('./routes/monsterhunter/update'));
|
||||
router.get('/monsterhunter/update', require('./routes/mhw/update'));
|
||||
router.get('/mhw/update', require('./routes/mhw/update'));
|
||||
router.get('/mhw/news', require('./routes/mhw/news'));
|
||||
|
||||
// 005.tv
|
||||
router.get('/005tv/zx/latest', require('./routes/005tv/zx'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://www.monsterhunter.com/world-iceborne/cn/news/';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.monsterhunter.com/world-iceborne/assets/data/cn/news.json?_=${+new Date()}`,
|
||||
});
|
||||
|
||||
let result = response.data.topics.map((item) => ({
|
||||
title: item.text,
|
||||
link: `https://www.monsterhunter.com${item.link}`,
|
||||
}));
|
||||
|
||||
result = await Promise.all(
|
||||
result.map(async (item) =>
|
||||
Promise.resolve(
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got.get(item.link.replace('/cn/', '/') + 'inc/contents_cn.html');
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
return {
|
||||
title:
|
||||
$('.h2')
|
||||
.text()
|
||||
.trim() || item.title,
|
||||
description: $('#contents').html(),
|
||||
link: item.link,
|
||||
author: 'MONSTER HUNTER WORLD: ICEBORNE',
|
||||
};
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '怪物猎人世界最新消息',
|
||||
link: url,
|
||||
item: result,
|
||||
};
|
||||
};
|
||||
|
|
@ -31,7 +31,10 @@ module.exports = async (ctx) => {
|
|||
.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('.text').text(),
|
||||
title: item
|
||||
.find('.text')
|
||||
.text()
|
||||
.trim(),
|
||||
pubDate: new Date(item.find('.date').text()).toUTCString(),
|
||||
link: url2 + item.attr('href'),
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue