From 8891ad1020f597fc263e8351f87bb553feacc9eb Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Wed, 2 Feb 2022 22:56:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=B1=86=E7=93=A3?= =?UTF-8?q?=E6=8B=9B=E8=81=98=20and=20refactor=20to=20V2=20standard=20(#89?= =?UTF-8?q?37)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add(route): add 豆瓣招聘 and change to V2 * Fix(route): fix typo of filename * Fix(route): sort routes * Fix(route): Update lib/v2/douban/router.js Co-authored-by: Tony Co-authored-by: Tony --- docs/social-media.md | 10 ++++ lib/radar-rules.js | 32 ----------- lib/router.js | 27 ---------- lib/{routes => v2}/douban/book/rank.js | 0 lib/{routes => v2}/douban/channel/subject.js | 0 lib/{routes => v2}/douban/channel/topic.js | 0 .../douban/commercialpress/latest.js | 0 lib/{routes => v2}/douban/event/hot.js | 0 lib/v2/douban/maintainer.js | 27 ++++++++++ .../douban => v2/douban/other}/bookstore.js | 0 .../douban => v2/douban/other}/celebrity.js | 0 .../douban/other}/classification.js | 0 .../douban => v2/douban/other}/doulist.js | 0 .../douban => v2/douban/other}/explore.js | 0 .../douban/other}/explore_column.js | 0 .../douban => v2/douban/other}/group.js | 2 +- lib/v2/douban/other/jobs.js | 33 ++++++++++++ .../douban => v2/douban/other}/later.js | 0 .../douban => v2/douban/other}/latest_book.js | 0 .../douban/other}/latest_music.js | 0 .../douban => v2/douban/other}/playing.js | 0 .../douban => v2/douban/other}/replied.js | 0 .../douban => v2/douban/other}/replies.js | 0 .../douban => v2/douban/other}/topic.js | 0 .../douban => v2/douban/other}/ustop.js | 0 .../douban => v2/douban/other}/weekly_best.js | 0 lib/{routes => v2}/douban/people/status.js | 0 lib/{routes => v2}/douban/people/wish.js | 0 lib/v2/douban/radar.js | 54 +++++++++++++++++++ lib/v2/douban/router.js | 27 ++++++++++ 30 files changed, 152 insertions(+), 60 deletions(-) rename lib/{routes => v2}/douban/book/rank.js (100%) rename lib/{routes => v2}/douban/channel/subject.js (100%) rename lib/{routes => v2}/douban/channel/topic.js (100%) rename lib/{routes => v2}/douban/commercialpress/latest.js (100%) rename lib/{routes => v2}/douban/event/hot.js (100%) create mode 100644 lib/v2/douban/maintainer.js rename lib/{routes/douban => v2/douban/other}/bookstore.js (100%) rename lib/{routes/douban => v2/douban/other}/celebrity.js (100%) rename lib/{routes/douban => v2/douban/other}/classification.js (100%) rename lib/{routes/douban => v2/douban/other}/doulist.js (100%) rename lib/{routes/douban => v2/douban/other}/explore.js (100%) rename lib/{routes/douban => v2/douban/other}/explore_column.js (100%) rename lib/{routes/douban => v2/douban/other}/group.js (97%) create mode 100644 lib/v2/douban/other/jobs.js rename lib/{routes/douban => v2/douban/other}/later.js (100%) rename lib/{routes/douban => v2/douban/other}/latest_book.js (100%) rename lib/{routes/douban => v2/douban/other}/latest_music.js (100%) rename lib/{routes/douban => v2/douban/other}/playing.js (100%) rename lib/{routes/douban => v2/douban/other}/replied.js (100%) rename lib/{routes/douban => v2/douban/other}/replies.js (100%) rename lib/{routes/douban => v2/douban/other}/topic.js (100%) rename lib/{routes/douban => v2/douban/other}/ustop.js (100%) rename lib/{routes/douban => v2/douban/other}/weekly_best.js (100%) rename lib/{routes => v2}/douban/people/status.js (100%) rename lib/{routes => v2}/douban/people/wish.js (100%) create mode 100644 lib/v2/douban/radar.js create mode 100644 lib/v2/douban/router.js diff --git a/docs/social-media.md b/docs/social-media.md index 979808a1df..a33af792e6 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -944,6 +944,16 @@ YouTube 官方亦有提供频道 RSS,形如 +### 豆瓣招聘 + + + +| 社会招聘 | 校园招聘 | 实习生招聘 | +| :------: | :------: | :--------: | +| social | campus | intern | + + + ## 饭否 ::: warning 注意 diff --git a/lib/radar-rules.js b/lib/radar-rules.js index 7e756aaf72..172a99f586 100644 --- a/lib/radar-rules.js +++ b/lib/radar-rules.js @@ -2416,38 +2416,6 @@ module.exports = { }, ], }, - 'douban.com': { - _name: '豆瓣', - www: [ - { - title: '用户的广播', - docs: 'https://docs.rsshub.app/social-media.html#dou-ban', - source: '/people/:user/', - target: (params, url, document) => { - const uid = document && document.querySelector('html').innerHTML.match(/"id":"([0-9]+)"/)[1]; - return uid ? `/douban/people/${uid}/status` : ''; - }, - }, - { - title: '小组-最新', - docs: 'https://docs.rsshub.app/social-media.html#dou-ban', - source: '/group/:groupid', - target: '/douban/group/:groupid', - }, - { - title: '小组-最热', - docs: 'https://docs.rsshub.app/social-media.html#dou-ban', - source: '/group/:groupid', - target: '/douban/group/:groupid/essence', - }, - { - title: '小组-精华', - docs: 'https://docs.rsshub.app/social-media.html#dou-ban', - source: '/group/:groupid', - target: '/douban/group/:groupid/elite', - }, - ], - }, 'okjike.com': { _name: '即刻', m: [ diff --git a/lib/router.js b/lib/router.js index 25d1c081c5..44031adb8f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -163,33 +163,6 @@ router.get('/pixiv/search/:keyword/:order?/:mode?', lazyloadRouteHandler('./rout // pixiv-fanbox router.get('/fanbox/:user?', lazyloadRouteHandler('./routes/fanbox/main')); -// 豆瓣 -router.get('/douban/movie/playing', lazyloadRouteHandler('./routes/douban/playing')); -router.get('/douban/movie/playing/:score', lazyloadRouteHandler('./routes/douban/playing')); -router.get('/douban/movie/playing/:score/:city', lazyloadRouteHandler('./routes/douban/playing')); -router.get('/douban/movie/later', lazyloadRouteHandler('./routes/douban/later')); -router.get('/douban/movie/ustop', lazyloadRouteHandler('./routes/douban/ustop')); -router.get('/douban/movie/weekly/:type?', lazyloadRouteHandler('./routes/douban/weekly_best')); -router.get('/douban/movie/classification/:sort?/:score?/:tags?', lazyloadRouteHandler('./routes/douban/classification.js')); -router.get('/douban/group/:groupid/:type?', lazyloadRouteHandler('./routes/douban/group')); -router.get('/douban/explore', lazyloadRouteHandler('./routes/douban/explore')); -router.get('/douban/music/latest/:area?', lazyloadRouteHandler('./routes/douban/latest_music')); -router.get('/douban/book/latest', lazyloadRouteHandler('./routes/douban/latest_book')); -router.get('/douban/event/hot/:locationId', lazyloadRouteHandler('./routes/douban/event/hot')); -router.get('/douban/commercialpress/latest', lazyloadRouteHandler('./routes/douban/commercialpress/latest')); -router.get('/douban/bookstore', lazyloadRouteHandler('./routes/douban/bookstore')); -router.get('/douban/book/rank/:type?', lazyloadRouteHandler('./routes/douban/book/rank')); -router.get('/douban/doulist/:id', lazyloadRouteHandler('./routes/douban/doulist')); -router.get('/douban/explore/column/:id', lazyloadRouteHandler('./routes/douban/explore_column')); -router.get('/douban/people/:userid/status/:routeParams?', lazyloadRouteHandler('./routes/douban/people/status.js')); -router.get('/douban/people/:userid/wish/:routeParams?', lazyloadRouteHandler('./routes/douban/people/wish.js')); -router.get('/douban/replies/:uid', lazyloadRouteHandler('./routes/douban/replies')); -router.get('/douban/replied/:uid', lazyloadRouteHandler('./routes/douban/replied')); -router.get('/douban/topic/:id/:sort?', lazyloadRouteHandler('./routes/douban/topic.js')); -router.get('/douban/channel/:id/:nav?', lazyloadRouteHandler('./routes/douban/channel/topic.js')); -router.get('/douban/channel/:id/subject/:nav', lazyloadRouteHandler('./routes/douban/channel/subject.js')); -router.get('/douban/celebrity/:id/:sort?', lazyloadRouteHandler('./routes/douban/celebrity.js')); - // 法律白話文運動 router.get('/plainlaw/archives', lazyloadRouteHandler('./routes/plainlaw/archives.js')); diff --git a/lib/routes/douban/book/rank.js b/lib/v2/douban/book/rank.js similarity index 100% rename from lib/routes/douban/book/rank.js rename to lib/v2/douban/book/rank.js diff --git a/lib/routes/douban/channel/subject.js b/lib/v2/douban/channel/subject.js similarity index 100% rename from lib/routes/douban/channel/subject.js rename to lib/v2/douban/channel/subject.js diff --git a/lib/routes/douban/channel/topic.js b/lib/v2/douban/channel/topic.js similarity index 100% rename from lib/routes/douban/channel/topic.js rename to lib/v2/douban/channel/topic.js diff --git a/lib/routes/douban/commercialpress/latest.js b/lib/v2/douban/commercialpress/latest.js similarity index 100% rename from lib/routes/douban/commercialpress/latest.js rename to lib/v2/douban/commercialpress/latest.js diff --git a/lib/routes/douban/event/hot.js b/lib/v2/douban/event/hot.js similarity index 100% rename from lib/routes/douban/event/hot.js rename to lib/v2/douban/event/hot.js diff --git a/lib/v2/douban/maintainer.js b/lib/v2/douban/maintainer.js new file mode 100644 index 0000000000..83aabf0db8 --- /dev/null +++ b/lib/v2/douban/maintainer.js @@ -0,0 +1,27 @@ +module.exports = { + '/book/latest': ['fengkx'], + '/book/rank/:type?': ['xyqfer', 'queensferryme'], + '/bookstore': ['xyqfer'], + '/celebrity/:id/:sort?': ['minimalistrojan'], + '/channel/:id/:nav?': ['umm233'], + '/channel/:id/subject/:nav': ['umm233'], + '/commercialpress/latest': ['xyqfer'], + '/doulist/:id': ['LogicJake'], + '/event/hot/:locationId': ['xyqfer'], + '/explore': ['clarkzsd'], + '/explore_column/:id': ['LogicJake'], + '/group/:groupid/:type?': ['DIYgod'], + '/jobs/:type': ['Fatpandac'], + '/movie/classification/:sort?/:score?/:tags?': ['zzwab'], + '/movie/later': ['DIYgod'], + '/movie/playing': ['DIYgod'], + '/movie/playing/:score': ['DIYgod'], + '/movie/ustop': ['DIYgod'], + '/movie/weekly/:type?': ['numm233', 'nczitzk'], + '/music/latest/:area?': ['fengkx', 'xyqfer'], + '/people/:userid/status/:routeParams': ['alfredcai'], + '/people/:userid/wish/:routeParams?': ['exherb'], + '/replied/:uid': ['nczitzk'], + '/replies/:uid': ['nczitzk'], + '/topic/:id/:sort?': ['LogicJake'], +}; diff --git a/lib/routes/douban/bookstore.js b/lib/v2/douban/other/bookstore.js similarity index 100% rename from lib/routes/douban/bookstore.js rename to lib/v2/douban/other/bookstore.js diff --git a/lib/routes/douban/celebrity.js b/lib/v2/douban/other/celebrity.js similarity index 100% rename from lib/routes/douban/celebrity.js rename to lib/v2/douban/other/celebrity.js diff --git a/lib/routes/douban/classification.js b/lib/v2/douban/other/classification.js similarity index 100% rename from lib/routes/douban/classification.js rename to lib/v2/douban/other/classification.js diff --git a/lib/routes/douban/doulist.js b/lib/v2/douban/other/doulist.js similarity index 100% rename from lib/routes/douban/doulist.js rename to lib/v2/douban/other/doulist.js diff --git a/lib/routes/douban/explore.js b/lib/v2/douban/other/explore.js similarity index 100% rename from lib/routes/douban/explore.js rename to lib/v2/douban/other/explore.js diff --git a/lib/routes/douban/explore_column.js b/lib/v2/douban/other/explore_column.js similarity index 100% rename from lib/routes/douban/explore_column.js rename to lib/v2/douban/other/explore_column.js diff --git a/lib/routes/douban/group.js b/lib/v2/douban/other/group.js similarity index 97% rename from lib/routes/douban/group.js rename to lib/v2/douban/other/group.js index 0e86534b99..0e8e7e9760 100644 --- a/lib/routes/douban/group.js +++ b/lib/v2/douban/other/group.js @@ -1,4 +1,4 @@ -const got = require('../../utils/got'); +const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { diff --git a/lib/v2/douban/other/jobs.js b/lib/v2/douban/other/jobs.js new file mode 100644 index 0000000000..398e9b451e --- /dev/null +++ b/lib/v2/douban/other/jobs.js @@ -0,0 +1,33 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const rootUrl = 'https://jobs.douban.com'; + +const titleMap = { + social: '社会招聘', + campus: '校园招聘', + intern: '实习生招聘', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type; + const url = `${rootUrl}/jobs/${type}`; + + const response = await got.get(url); + const $ = cheerio.load(response.data); + const list = $('div.mod.position'); + + const items = list + .map((_, item) => ({ + title: $(item).find('h3').text(), + link: `${url}#${$(item).find('h3').attr('id')}`, + description: $(item).find('div.bd').html(), + })) + .get(); + + ctx.state.data = { + title: `豆瓣${titleMap[type]}`, + link: url, + item: items, + }; +}; diff --git a/lib/routes/douban/later.js b/lib/v2/douban/other/later.js similarity index 100% rename from lib/routes/douban/later.js rename to lib/v2/douban/other/later.js diff --git a/lib/routes/douban/latest_book.js b/lib/v2/douban/other/latest_book.js similarity index 100% rename from lib/routes/douban/latest_book.js rename to lib/v2/douban/other/latest_book.js diff --git a/lib/routes/douban/latest_music.js b/lib/v2/douban/other/latest_music.js similarity index 100% rename from lib/routes/douban/latest_music.js rename to lib/v2/douban/other/latest_music.js diff --git a/lib/routes/douban/playing.js b/lib/v2/douban/other/playing.js similarity index 100% rename from lib/routes/douban/playing.js rename to lib/v2/douban/other/playing.js diff --git a/lib/routes/douban/replied.js b/lib/v2/douban/other/replied.js similarity index 100% rename from lib/routes/douban/replied.js rename to lib/v2/douban/other/replied.js diff --git a/lib/routes/douban/replies.js b/lib/v2/douban/other/replies.js similarity index 100% rename from lib/routes/douban/replies.js rename to lib/v2/douban/other/replies.js diff --git a/lib/routes/douban/topic.js b/lib/v2/douban/other/topic.js similarity index 100% rename from lib/routes/douban/topic.js rename to lib/v2/douban/other/topic.js diff --git a/lib/routes/douban/ustop.js b/lib/v2/douban/other/ustop.js similarity index 100% rename from lib/routes/douban/ustop.js rename to lib/v2/douban/other/ustop.js diff --git a/lib/routes/douban/weekly_best.js b/lib/v2/douban/other/weekly_best.js similarity index 100% rename from lib/routes/douban/weekly_best.js rename to lib/v2/douban/other/weekly_best.js diff --git a/lib/routes/douban/people/status.js b/lib/v2/douban/people/status.js similarity index 100% rename from lib/routes/douban/people/status.js rename to lib/v2/douban/people/status.js diff --git a/lib/routes/douban/people/wish.js b/lib/v2/douban/people/wish.js similarity index 100% rename from lib/routes/douban/people/wish.js rename to lib/v2/douban/people/wish.js diff --git a/lib/v2/douban/radar.js b/lib/v2/douban/radar.js new file mode 100644 index 0000000000..ea49ac1c65 --- /dev/null +++ b/lib/v2/douban/radar.js @@ -0,0 +1,54 @@ +module.exports = { + 'douban.com': { + _name: '豆瓣', + www: [ + { + title: '用户的广播', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/people/:user/', + target: (params, url, document) => { + const uid = document && document.querySelector('html').innerHTML.match(/"id":"([0-9]+)"/)[1]; + return uid ? `/douban/people/${uid}/status` : ''; + }, + }, + { + title: '小组-最新', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/group/:groupid', + target: '/douban/group/:groupid', + }, + { + title: '小组-最热', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/group/:groupid', + target: '/douban/group/:groupid/essence', + }, + { + title: '小组-精华', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/group/:groupid', + target: '/douban/group/:groupid/elite', + }, + ], + jobs: [ + { + title: '社会招聘', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/jobs/social', + target: '/jobs/social', + }, + { + title: '校园招聘', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/jobs/campus', + target: '/jobs/campus', + }, + { + title: '实习生招聘', + docs: 'https://docs.rsshub.app/social-media.html#dou-ban', + source: '/jobs/intern', + target: '/jobs/intern', + }, + ], + }, +}; diff --git a/lib/v2/douban/router.js b/lib/v2/douban/router.js new file mode 100644 index 0000000000..d40f443271 --- /dev/null +++ b/lib/v2/douban/router.js @@ -0,0 +1,27 @@ +module.exports = function (router) { + router.get('/book/latest', require('./other/latest_book')); + router.get('/book/rank/:type?', require('./book/rank')); + router.get('/bookstore', require('./other/bookstore')); + router.get('/celebrity/:id/:sort?', require('./other/celebrity.js')); + router.get('/channel/:id/subject/:nav', require('./channel/subject.js')); + router.get('/channel/:id/:nav?', require('./channel/topic.js')); + router.get('/commercialpress/latest', require('./commercialpress/latest')); + router.get('/doulist/:id', require('./other/doulist')); + router.get('/event/hot/:locationId', require('./event/hot')); + router.get('/explore', require('./other/explore')); + router.get('/explore/column/:id', require('./other/explore_column')); + router.get('/group/:groupid/:type?', require('./other/group')); + router.get('/jobs/:type', require('./other/jobs.js')); + router.get('/movie/classification/:sort?/:score?/:tags?', require('./other/classification.js')); + router.get('/movie/later', require('./other/later')); + router.get('/movie/playing', require('./other/playing')); + router.get('/movie/playing/:score', require('./other/playing')); + router.get('/movie/ustop', require('./other/ustop')); + router.get('/movie/weekly/:type?', require('./other/weekly_best')); + router.get('/music/latest/:area?', require('./other/latest_music')); + router.get('/people/:userid/status/:routeParams?', require('./people/status.js')); + router.get('/people/:userid/wish/:routeParams?', require('./people/wish.js')); + router.get('/replied/:uid', require('./other/replied')); + router.get('/replies/:uid', require('./other/replies')); + router.get('/topic/:id/:sort?', require('./other/topic.js')); +};