From c0d993b4fa06f003665ed5d63ebc0d50d20f02dc Mon Sep 17 00:00:00 2001 From: sanmmmm Date: Fri, 26 Jul 2019 10:52:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20=E4=B8=80=E5=85=9C?= =?UTF-8?q?=E7=B3=96=20(#2684)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix docs format error * feat: 新增一兜糖 --- docs/other.md | 26 ++++++++++++++++++++ docs/shopping.md | 12 ++++----- docs/university.md | 12 ++++----- lib/router.js | 6 +++++ lib/routes/yidoutang/case.js | 46 +++++++++++++++++++++++++++++++++++ lib/routes/yidoutang/guide.js | 36 +++++++++++++++++++++++++++ lib/routes/yidoutang/index.js | 33 +++++++++++++++++++++++++ lib/routes/yidoutang/mtest.js | 34 ++++++++++++++++++++++++++ 8 files changed, 193 insertions(+), 12 deletions(-) create mode 100644 lib/routes/yidoutang/case.js create mode 100644 lib/routes/yidoutang/guide.js create mode 100644 lib/routes/yidoutang/index.js create mode 100644 lib/routes/yidoutang/mtest.js diff --git a/docs/other.md b/docs/other.md index 03634b056..ea0dcdf2a 100644 --- a/docs/other.md +++ b/docs/other.md @@ -939,6 +939,7 @@ type 为 all 时,category 参数不支持 cost 和 free | (空) | My01 | My02 | My03 | My04 | + ## 维基百科 ### 中国大陆新闻动态 @@ -1054,6 +1055,31 @@ type 为 all 时,category 参数不支持 cost 和 free +## 一兜糖 + +### 首页精选 + + + +### 文章 + + + +### 众测 + + + +### 全屋记 + + + +类型 + +| 默认 | 最热 | 最新 | +| ------- | ---- | ---- | +| default | hot | new | + + ## 油价 ### 今日油价 diff --git a/docs/shopping.md b/docs/shopping.md index 5bd61f7e6..2295ec343 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -4,6 +4,12 @@ pageClass: routes # 购物 +## Artand + +### 用户新作 + + + ## Westore ### 新品 @@ -159,9 +165,3 @@ pageClass: routes ### 小米有品每日上新 - -## Artand - -### 用户新作 - - diff --git a/docs/university.md b/docs/university.md index c36870db0..2b55ec5c4 100644 --- a/docs/university.md +++ b/docs/university.md @@ -404,6 +404,12 @@ category 列表: +## 南京工业大学 + +### 南京工业大学教务处 + + + ## 南京航空航天大学 ### 教务通知 @@ -954,9 +960,3 @@ https://rsshub.app/**nuist**/`bulletin` 或 https://rsshub.app/**nuist**/`bullet ### 数据科学与计算机学院动态 - -## 南京工业大学 - -### 南京工业大学教务处 - - diff --git a/lib/router.js b/lib/router.js index f7c76a152..ef21edb7d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1562,4 +1562,10 @@ router.get('/10000link/news/:category?', require('./routes/10000link/news')); // Artand router.get('/artand/user/work/:uid', require('./routes/artand/user/work')); +// 一兜糖 +router.get('/yidoutang/index', require('./routes/yidoutang/index.js')); +router.get('/yidoutang/guide', require('./routes/yidoutang/guide.js')); +router.get('/yidoutang/mtest', require('./routes/yidoutang/mtest.js')); +router.get('/yidoutang/case/:type', require('./routes/yidoutang/case.js')); + module.exports = router; diff --git a/lib/routes/yidoutang/case.js b/lib/routes/yidoutang/case.js new file mode 100644 index 000000000..1d5e48356 --- /dev/null +++ b/lib/routes/yidoutang/case.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { type = 'default' } = ctx.params; + const urlPath = { + default: '', + hot: '/0-2-0-0-0-0/', + new: '/0-1-0-0-0-0/', + }[type]; + const url = `http://www.yidoutang.com/case${urlPath}`; + const response = await got(url); + const $ = cheerio.load(response.data); + + const items = $('.main .case-items > .case-item') + .map((_, ele) => { + const $item = cheerio.load(ele); + const baseInfoNode = $item('.info > .text'); + const title = baseInfoNode.find('.title').text(); + const desc = baseInfoNode.find('.desc').text(); + const link = baseInfoNode.find('a').attr('href'); + + const thumbnail = $item('.img-box img').attr('src'); + const author = $item('.user a').text(); + + return { + title, + link, + description: [`简介: ${desc}`, ``].join('
'), + author, + }; + }) + .get(); + + const typeLabel = { + default: '默认', + hot: '热门', + new: '最新', + }[type]; + ctx.state.data = { + title: `一兜糖 - 全屋记 - ${typeLabel}`, + description: `一兜糖 - 全屋记 - ${typeLabel}`, + link: url, + item: items, + }; +}; diff --git a/lib/routes/yidoutang/guide.js b/lib/routes/yidoutang/guide.js new file mode 100644 index 000000000..133e4535e --- /dev/null +++ b/lib/routes/yidoutang/guide.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'http://www.yidoutang.com/guide.html'; + const response = await got(url); + const $ = cheerio.load(response.data); + + const items = $('.main .guide-items > .guide-item') + .map((_, ele) => { + const $item = cheerio.load(ele); + const titleNode = $item('.title > a').first(); + const title = titleNode.text(); + const link = titleNode.attr('href'); + const thumbnail = $item('a > img') + .first() + .attr('src'); + + const infoNode = $item('.info'); + const desc = infoNode.find('.desc').text(); + const author = infoNode.find('.user a').text(); + return { + title, + link, + description: [`简介: ${desc}`, ``].join('
'), + author, + }; + }) + .get(); + ctx.state.data = { + title: '一兜糖 - 文章', + description: '一兜糖 - 文章', + link: url, + item: items, + }; +}; diff --git a/lib/routes/yidoutang/index.js b/lib/routes/yidoutang/index.js new file mode 100644 index 000000000..3fd540f85 --- /dev/null +++ b/lib/routes/yidoutang/index.js @@ -0,0 +1,33 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'http://www.yidoutang.com/'; + const response = await got(url); + const $ = cheerio.load(response.data); + + const items = $('.main > .article') + .map((_, ele) => { + const $item = cheerio.load(ele); + const baseInfoNode = $item('.title > a'); + const title = baseInfoNode.text(); + const link = baseInfoNode.attr('href'); + const thumbnail = $item('.article > a > img').attr('delayload'); + const desc = $item('.abstract').text(); + const tip = $item('.tip').text(); + const author = $item('.avatar a').text(); + return { + title, + link, + description: [`分类: ${tip}`, `简介: ${desc}`, ``].join('
'), + author, + }; + }) + .get(); + ctx.state.data = { + title: '一兜糖 - 精选', + description: '一兜糖 - 精选', + link: url, + item: items, + }; +}; diff --git a/lib/routes/yidoutang/mtest.js b/lib/routes/yidoutang/mtest.js new file mode 100644 index 000000000..58a334661 --- /dev/null +++ b/lib/routes/yidoutang/mtest.js @@ -0,0 +1,34 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const url = 'http://www.yidoutang.com/mtest'; + const response = await got(url); + const $ = cheerio.load(response.data); + + const items = $('.zc-bd .zc-bd-left > .clearfix > a') + .map((_, ele) => { + const $item = cheerio.load(ele); + const link = ele.attribs.href; + const thumbnail = $item('.top > img').attr('src'); + const deadline = $item('.top > .time').text(); + const otherInfoArr = $item('.bottom') + .text() + .trim() + .split('\n'); + const title = otherInfoArr[0]; + + return { + title, + link, + description: [deadline, ...otherInfoArr, ``].filter((str) => !!str.trim()).join('
'), + }; + }) + .get(); + ctx.state.data = { + title: '一兜糖 - 众测', + description: '一兜糖 - 众测', + link: url, + item: items, + }; +};