diff --git a/docs/new-media.md b/docs/new-media.md index 71b6315dc..6c35bff61 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -753,6 +753,28 @@ area 分区选项 +## 梅花网 + +### 作品 + + + +| 最新 | 热门 | 推荐 | +| ------ | ---- | --------- | +| latest | hot | recommend | + + + +### 文章 + + + +| 最新 | 热门 | +| ------ | ---- | +| latest | hot | + + + ## 镁客网 im2maker ### 镁客网频道 diff --git a/lib/router.js b/lib/router.js index 5f897a645..4d7058436 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2980,6 +2980,10 @@ router.get('/12379', require('./routes/12379/index')); router.get('/ngbj/today', require('./routes/niaogebiji/today')); router.get('/ngbj/cat/:cat', require('./routes/niaogebiji/cat')); +// 梅花网 +router.get('/meihua/shots/:caty', require('./routes/meihua/shots')); +router.get('/meihua/article/:caty', require('./routes/meihua/article')); + // 看点快报 router.get('/kuaibao', require('./routes/kuaibao/index')); diff --git a/lib/routes/meihua/article.js b/lib/routes/meihua/article.js new file mode 100644 index 000000000..f46317af0 --- /dev/null +++ b/lib/routes/meihua/article.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + latest: { + link: 'article!2', + title: '最新', + }, + hot: { + link: 'article!3', + title: '热门', + }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const currentUrl = `https://www.meihua.info/${cfg.link}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const data = JSON.parse(response.data.match(/"compositionStore":(.*?),"detailStore":/)[1]); + + const shotList = data.compositionsData.list.map((item) => ({ + title: item.title, + link: `https://www.meihua.info/article/${item.compositionId}`, + pubDate: new Date(item.gmtPublish).toUTCString(), + })); + + const items = await Promise.all( + shotList.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const contentResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(contentResponse.data); + + item.description = content('#article-content-html').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `${cfg.title}文章 - 梅花网`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/routes/meihua/shots.js b/lib/routes/meihua/shots.js new file mode 100644 index 000000000..c2fd079f4 --- /dev/null +++ b/lib/routes/meihua/shots.js @@ -0,0 +1,59 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const config = { + recommend: { + link: 'shots!1!0!0!0!0', + title: '推荐', + }, + latest: { + link: 'shots!2!0!0!0!0', + title: '最新', + }, + hot: { + link: 'shots!3!0!0!0!0', + title: '热门', + }, +}; + +module.exports = async (ctx) => { + const cfg = config[ctx.params.caty]; + if (!cfg) { + throw Error('Bad category. See docs'); + } + + const currentUrl = `https://www.meihua.info/${cfg.link}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const data = JSON.parse(response.data.match(/"shotsStore":(.*?),"commentStore":/)[1]); + + const shotList = data.shotsData.list.map((item) => ({ + title: item.title, + link: `https://www.meihua.info/shots/${item.compositionId}`, + pubDate: new Date(item.gmtPublish).toUTCString(), + })); + + const items = await Promise.all( + shotList.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const contentResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(contentResponse.data); + + item.description = content('div.summary').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: `${cfg.title}作品 - 梅花网`, + link: currentUrl, + item: items, + }; +};