diff --git a/docs/new-media.md b/docs/new-media.md index b860fcad53..6573bf5048 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1994,6 +1994,24 @@ column 为 third 时可选的 category: +## 软餐 + +### 首页 + + + +### 分类 + + + +### 标签 + + + +### 搜索 + + + ## 少数派 sspai ### 最新上架付费专栏 diff --git a/lib/v2/ruancan/index.js b/lib/v2/ruancan/index.js new file mode 100644 index 0000000000..d813048885 --- /dev/null +++ b/lib/v2/ruancan/index.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const todo = ctx.params.do ?? ''; + const keyword = ctx.params.keyword ?? ''; + + const rootUrl = 'https://www.ruancan.com'; + const currentUrl = `${rootUrl}${todo ? (todo === 'search' ? `/page/1?s=${keyword}` : `/${todo}/${keyword}`) : ''}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.item-title a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.author = content('.author-name').text(); + item.pubDate = parseDate(content('.published').attr('datetime')); + item.description = content('.entry-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/ruancan/maintainer.js b/lib/v2/ruancan/maintainer.js new file mode 100644 index 0000000000..a4c1f4cb65 --- /dev/null +++ b/lib/v2/ruancan/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/ruancan': ['nczitzk'], + '/ruancan/sort/:sort?': ['nczitzk'], + '/ruancan/tag/:tag': ['nczitzk'], + '/ruancan/search/:keyword?': ['nczitzk'], +}; diff --git a/lib/v2/ruancan/radar.js b/lib/v2/ruancan/radar.js new file mode 100644 index 0000000000..32118f14f1 --- /dev/null +++ b/lib/v2/ruancan/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'ruancan.com': { + _name: '软餐', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/new-media.html#ruan-can-shou-ye', + source: ['/'], + target: '/ruancan', + }, + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#ruan-can-fen-lei', + source: ['/sort/:sort', '/'], + target: '/ruancan/sort/:sort', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/new-media.html#ruan-can-biao-qian', + source: ['/tag/:tag', '/'], + target: '/ruancan/tag/:tag', + }, + ], + }, +}; diff --git a/lib/v2/ruancan/router.js b/lib/v2/ruancan/router.js new file mode 100644 index 0000000000..85893161dc --- /dev/null +++ b/lib/v2/ruancan/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:do?/:keyword?', require('./index')); +};