From 645e6c0be91816d23129a06e3865d0db689f35db Mon Sep 17 00:00:00 2001 From: Keo Date: Thu, 29 Feb 2024 08:52:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=88=BA=E7=8C=AC?= =?UTF-8?q?=E7=8C=AB=20(#14592)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add 刺猬猫 * fix getting chapter content * add docs & radar; fix image * update default limit * do not fetch chapter content if chapter is locked --- lib/v2/ciweimao/chapter.js | 61 +++++++++++++++++++++++++++++++++ lib/v2/ciweimao/maintainer.js | 3 ++ lib/v2/ciweimao/radar.js | 13 +++++++ lib/v2/ciweimao/router.js | 3 ++ website/docs/routes/reading.mdx | 6 ++++ 5 files changed, 86 insertions(+) create mode 100644 lib/v2/ciweimao/chapter.js create mode 100644 lib/v2/ciweimao/maintainer.js create mode 100644 lib/v2/ciweimao/radar.js create mode 100644 lib/v2/ciweimao/router.js diff --git a/lib/v2/ciweimao/chapter.js b/lib/v2/ciweimao/chapter.js new file mode 100644 index 000000000..9c2f71956 --- /dev/null +++ b/lib/v2/ciweimao/chapter.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + const limit = Number.parseInt(ctx.query.limit) || 10; + + const baseUrl = 'https://wap.ciweimao.com'; + const chapterUrl = 'https://mip.ciweimao.com'; + + const { data: response } = await got(`${baseUrl}/book/${id}`); + const $ = cheerio.load(response); + + const firstChapterUrl = $('ul.catalogue-list li a').attr('href'); + const firstChapterId = firstChapterUrl.substring(firstChapterUrl.lastIndexOf('/') + 1); + + const { data: chapters } = await got(`${chapterUrl}/chapter/${id}/${firstChapterId}`); + const $c = cheerio.load(chapters); + + const list = $c('ul.book-chapter li a') + .slice(-limit) + .toArray() + .map((item) => { + item = $(item); + return { + chapterLocked: item.find('h3 i.icon-lock').length > 0, + title: item.find('h3').text(), + pubDate: timezone(parseDate(item.find('p').text().replace('发布于 ', '')), +8), + link: item.attr('href'), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (item.chapterLocked) { + return item; + } + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + const content = $('div.read-bd'); + content.find('span, a').remove(); + content.find('p').removeAttr('class'); + item.description = content.html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `刺猬猫 ${$('.book-name').text()}`, + link: `${baseUrl}/book/${id}`, + description: $('.book-desc div p').text(), + image: $('meta[name=image]').attr('content'), + item: items, + }; +}; diff --git a/lib/v2/ciweimao/maintainer.js b/lib/v2/ciweimao/maintainer.js new file mode 100644 index 000000000..aca9a836c --- /dev/null +++ b/lib/v2/ciweimao/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/chapter/:id': ['keocheung'], +}; diff --git a/lib/v2/ciweimao/radar.js b/lib/v2/ciweimao/radar.js new file mode 100644 index 000000000..14eb9238f --- /dev/null +++ b/lib/v2/ciweimao/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ciweimao.com': { + _name: '刺猬猫', + wap: [ + { + title: '章节', + docs: 'https://docs.rsshub.app/routes/reading#ci-wei-mao', + source: ['/book/:id'], + target: '/ciweimao/chapter/:id', + }, + ], + }, +}; diff --git a/lib/v2/ciweimao/router.js b/lib/v2/ciweimao/router.js new file mode 100644 index 000000000..81d0ce005 --- /dev/null +++ b/lib/v2/ciweimao/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/chapter/:id', require('./chapter')); +}; diff --git a/website/docs/routes/reading.mdx b/website/docs/routes/reading.mdx index 10e5ab1fe..6f69c7ba6 100644 --- a/website/docs/routes/reading.mdx +++ b/website/docs/routes/reading.mdx @@ -218,6 +218,12 @@ ::: +## 刺猬猫 {#ci-wei-mao} + +### 章节 {#ci-wei-mao-zhang-jie} + + + ## 单向空间 {#dan-xiang-kong-jian} ### 单读 {#dan-xiang-kong-jian-dan-du}