diff --git a/docs/reading.md b/docs/reading.md index 57f3410fe6..bda3160266 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -161,6 +161,16 @@ count 的取值范围为 1-12,为防止请求次数过多,推荐设置为 5 +## 孔夫子旧书网 + +### 用户动态 + + + +### 店铺上架 + + + ## 飘天文学 ### 章节 diff --git a/lib/router.js b/lib/router.js index 7d7d425a16..8aef06e1df 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3129,20 +3129,14 @@ router.get('/shiep/:type', require('./routes/universities/shiep/index')); // 福建新闻 router.get('/fjnews/:city/:limit', require('./routes/fjnews/fznews')); - -router.get('/fjnews/fj/30', require('./routes/fjnews/fznews')); - -// 福州新闻 -router.get('/fjnews/fz/30', require('./routes/fjnews/fznews')); - -// 九江新闻jjnews router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews')); -// XMind -router.get('/xmind/mindmap/:lang?', require('./routes/xmind/mindmap')); - // 孔夫子旧书网 router.get('/kongfz/people/:id', require('./routes/kongfz/people')); +router.get('/kongfz/shop/:id/:cat?', require('./routes/kongfz/shop')); + +// XMind +router.get('/xmind/mindmap/:lang?', require('./routes/xmind/mindmap')); // 小刀娱乐网 router.get('/x6d/:id?', require('./routes/x6d/index')); diff --git a/lib/routes/kongfz/shop.js b/lib/routes/kongfz/shop.js new file mode 100644 index 0000000000..16a02be74f --- /dev/null +++ b/lib/routes/kongfz/shop.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.cat = ctx.params.cat ? '/cat_' + ctx.params.cat : ''; + + const shopUrl = `http://shop.kongfz.com/${ctx.params.id}${ctx.params.cat}`; + + const shopResponse = await got({ + method: 'get', + url: shopUrl, + }); + + const $ = cheerio.load(shopResponse.data); + + const list = $(ctx.params.cat ? 'div.list-content div.item-row' : 'div.newest_content span.rareBook_content_list') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const a = ctx.params.cat ? item.find('a').eq(0) : item.find('div.rareBook_content_title a'); + return { + title: item.text(), + link: a.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); + + content('#eventreport').remove(); + content('div.buy-group').remove(); + content('div.weixin-popup-bg').remove(); + + const imgHtml = ``; + + item.description = content('div.major-function').html() + imgHtml; + item.pubDate = new Date(content('span.up-book-date-time').text()); + + return item; + }) + ) + ); + + const titleSplit = $('title').text().split('_'); + + ctx.state.data = { + title: `孔夫子旧书网 - ${titleSplit[titleSplit.length - 2]}`, + link: shopUrl, + item: items, + }; +};