diff --git a/docs/blog.md b/docs/blog.md index 9c12adfc1a..bcd0c95293 100644 --- a/docs/blog.md +++ b/docs/blog.md @@ -90,6 +90,12 @@ pageClass: routes +## yuzu emulator + +### Entry + + + ## 阿里云系统组技术博客 ### 首页 diff --git a/docs/en/blog.md b/docs/en/blog.md index f80e1ba19d..0053952bde 100644 --- a/docs/en/blog.md +++ b/docs/en/blog.md @@ -42,3 +42,8 @@ pageClass: routes +## yuzu emulator + +### Entry + + \ No newline at end of file diff --git a/lib/router.js b/lib/router.js index 4930175716..b4d788346f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4169,6 +4169,9 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese')); // Harvard router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog')); +// yuzu emulator +router.get('/yuzu-emu/entry', require('./routes/yuzu-emu/entry')); + // 温州大学 router.get('/wzu/news', require('./routes/universities/wzu/news')); diff --git a/lib/routes/yuzu-emu/entry.js b/lib/routes/yuzu-emu/entry.js new file mode 100644 index 0000000000..1110b053dc --- /dev/null +++ b/lib/routes/yuzu-emu/entry.js @@ -0,0 +1,53 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://yuzu-emu.org'; + const currentUrl = `${rootUrl}/entry`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.blog-entry-header') + .map((_, item) => { + item = $(item); + + return { + link: item.attr('data-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 meta = content('.h3').text().trim().split(' on '); + + item.title = content('.title').text(); + item.description = content('.content').html(); + item.author = meta[0].replace('Written by ', ''); + item.pubDate = parseDate(meta[1], 'MMMM DD YYYY'); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};