diff --git a/docs/reading.md b/docs/reading.md index f0b157826f..81f8457897 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -10,6 +10,18 @@ pageClass: routes +## Kindle Unlimited + +### 会员限时免费读书单 + + + +| 本月书单 | 好评返场 | 次月预告 | +| -------- | -------- | -------- | +| this | back | next | + + + ## Mobilism ### eBook Releases diff --git a/lib/router.js b/lib/router.js index 6224f0a728..b7aa6d7156 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3384,6 +3384,9 @@ router.get('/dev.to/top/:period', require('./routes/dev.to/top')); router.get('/gameres/hot', require('./routes/gameres/hot')); router.get('/gameres/list/:id', require('./routes/gameres/list')); +// Amazon +router.get('/amazon/ku/:type?', require('./routes/amazon/ku')); + // Citavi 中文网站论坛 router.get('/citavi/:caty?', require('./routes/citavi/index')); diff --git a/lib/routes/amazon/ku.js b/lib/routes/amazon/ku.js new file mode 100644 index 0000000000..35f34239f6 --- /dev/null +++ b/lib/routes/amazon/ku.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + this: '2037295071', + back: '2330861071', + next: '2037296071', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'this'; + + const node = config[type]; + if (!node) { + throw Error('Bad type. See docs'); + } + + const rootUrl = `https://www.amazon.cn/b?node=${node}`; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + const list = $('.s-access-detail-page') + .map((_, item) => { + item = $(item); + return { + link: item.attr('href'), + title: item.attr('title'), + }; + }) + .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); + + item.author = content('span.author').text(); + item.description = content('#ebooks-img-canvas').html() + content('#detailBullets_feature_div').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `KU会员限时免费读 - ${$('title').text().split('-')[1]}`, + link: rootUrl, + item: items, + }; +};