diff --git a/docs/game.md b/docs/game.md index 9c13ab93e4..1297d7ef69 100644 --- a/docs/game.md +++ b/docs/game.md @@ -192,3 +192,9 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 ### 公告 + +## MaxNews + +### Dota 2 + + diff --git a/lib/router.js b/lib/router.js index b117e32946..d9487d5762 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1310,6 +1310,9 @@ router.get('/enclavebooks/category/:id?', require('./routes/enclavebooks/categor router.get('/dsndsht23/:subforumid', require('./routes/dsndsht23/index')); router.get('/dsndsht23', require('./routes/dsndsht23/index')); +// MaxNews - DotA 2 +router.get('/maxnews/dota2', require('./routes/maxnews/dota2')); + // 数英网最新文章 router.get('/digitaling/index', require('./routes/digitaling/index')); diff --git a/lib/routes/maxnews/dota2.js b/lib/routes/maxnews/dota2.js new file mode 100644 index 0000000000..a2fd638c4a --- /dev/null +++ b/lib/routes/maxnews/dota2.js @@ -0,0 +1,45 @@ +const axios = require('@/utils/axios'); + +const sourceTimezoneOffset = -8; +module.exports = async (ctx) => { + const url = 'https://news.maxjia.com/maxnews/app/list/'; + const res = await axios.get(url); + const articles = (res.data || {}).result || []; + const out = await Promise.all( + articles.map(async (article) => { + const link = article.newUrl; + const cache = await ctx.cache.get(link); + if (cache) { + return JSON.parse(cache); + } + + const guid = article.newsid; + const title = article.title; + const time = new Date(article.date); + time.setTime(time.getTime() + (sourceTimezoneOffset - time.getTimezoneOffset() / 60) * 60 * 60 * 1000); + const pubDate = time.toUTCString(); + + const detailJsonLink = article.detail_json; + const detailRes = await axios.get(detailJsonLink); + const description = detailRes.data.content; + + const item = { + title, + description, + pubDate, + link, + guid, + }; + + ctx.cache.set(link, JSON.stringify(item)); + + return item; + }) + ); + + ctx.state.data = { + title: 'MaxNews - Dota 2', + link: 'https://www.maxjia.com', + item: out, + }; +};