From daeace687d869875fc68809be2290a4f87e051b8 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 3 Oct 2020 07:14:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E5=A6=88=E5=92=AA=E5=B8=AE=20(#5?= =?UTF-8?q?771)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Henry Wang --- docs/new-media.md | 24 ++++++++++++++++++++++++ lib/router.js | 3 +++ lib/routes/mamibuy/index.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 lib/routes/mamibuy/index.js diff --git a/docs/new-media.md b/docs/new-media.md index 95cd52c351..d509a4f9db 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -950,6 +950,30 @@ area 分区选项 +## 妈咪帮 + + + +分类 + +| 全分類 | 小兒醫護 | 幼兒教育 | 育兒成長 | 母乳餵哺 | 寶寶飲食 | 用品交流 | 女人聊天 | 居家生活 | 親子旅遊 / 好去處 | 媽咪扮靚 | 生活閒談 | 懷孕交流 | +| ------ | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | ----------------- | -------- | -------- | -------- | +| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | + +岁数 + +| 不限 | 懷孕中 | 生產後 | 0~1 歲 | 1~3 歲 | 3~6 歲 | 6 歲以上 | +| ---- | ------ | ------ | ------ | ------ | ------ | -------- | +| 0 | 1 | 2 | 3 | 4 | 5 | 6 | + +排序 + +| 最新 | 推薦 | 熱門 | +| ---- | ---- | ---- | +| 1 | 2 | 3 | + + + ## 梅花网 ### 作品 diff --git a/lib/router.js b/lib/router.js index a636c2aed8..89f567a781 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3242,6 +3242,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index')); // CGTN router.get('/cgtn/top', require('./routes/cgtn/top')); +// 妈咪帮 +router.get('/mamibuy/:caty?/:age?/:sort?', require('./routes/mamibuy/index')); + // Mercari router.get('/mercari/:type/:id', require('./routes/mercari/index')); diff --git a/lib/routes/mamibuy/index.js b/lib/routes/mamibuy/index.js new file mode 100644 index 0000000000..0f678e6389 --- /dev/null +++ b/lib/routes/mamibuy/index.js @@ -0,0 +1,35 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + ctx.params.caty = ctx.params.caty || '0'; + ctx.params.age = ctx.params.age || '0'; + ctx.params.sort = ctx.params.sort || '1'; + + const currentUrl = `https://mamibuy.com.hk/talk/article/?cid=${ctx.params.caty}&aid=${ctx.params.age}&s=${ctx.params.sort}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + + const list = $('div.masonry-item') + .map((_, item) => { + item = $(item); + const photos = item.find('div.content-photo').html(); + const title = item.find('div.content-title').text(); + const subtitle = item.find('div.content-subtitle').text(); + return { + title, + link: item.find('a.link-black').attr('href'), + description: `${photos}

${subtitle}

`, + }; + }) + .get(); + + ctx.state.data = { + title: `MamiBuy 媽咪幫`, + link: currentUrl, + item: list, + }; +};