diff --git a/docs/program-update.md b/docs/program-update.md index e10dd06eaa..f3cf364ca3 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -200,6 +200,12 @@ pageClass: routes +## OneNote Gem Add-Ins + +### Release History + + + ## PlayStation ### PlayStation 4 系统更新纪录 diff --git a/lib/router.js b/lib/router.js index dd18399fd7..52dba550e4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news')); router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt')); router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic')); +// OneNote Gem Add-Ins +router.get('/onenotegem/release', require('./routes/onenotegem/release')); + // Mind42 router.get('/mind42/tag/:id', require('./routes/mind42/tag')); router.get('/mind42/search/:keyword', require('./routes/mind42/search')); diff --git a/lib/routes/onenotegem/release.js b/lib/routes/onenotegem/release.js new file mode 100644 index 0000000000..c691df661d --- /dev/null +++ b/lib/routes/onenotegem/release.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'http://www.onenotegem.com'; + const currentUrl = `${rootUrl}/a/release`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.paragraph ul li a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + const title = content('h1.wsite-content-title'); + + item.description = title.next().next().next().html(); + item.pubDate = new Date(title.next().text()).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: 'OneNote Gem Addins Release History', + link: currentUrl, + item: items, + }; +};