feat(route): add 刺猬猫 (#14592)

* add 刺猬猫

* fix getting chapter content

* add docs & radar; fix image

* update default limit

* do not fetch chapter content if chapter is locked
This commit is contained in:
Keo
2024-02-29 08:52:24 +08:00
committed by GitHub
parent cbbd82918e
commit 645e6c0be9
5 changed files with 86 additions and 0 deletions
+61
View File
@@ -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,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/chapter/:id': ['keocheung'],
};
+13
View File
@@ -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',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/chapter/:id', require('./chapter'));
};
+6
View File
@@ -218,6 +218,12 @@
:::
</Route>
## 刺猬猫 {#ci-wei-mao}
### 章节 {#ci-wei-mao-zhang-jie}
<Route author="keocheung" example="/ciweimao/chapter/100043404" path="/ciweimao/chapter/:id" paramsDesc={['小说 id, 可在对应小说页 URL 中找到']} radar="1" />
## 单向空间 {#dan-xiang-kong-jian}
### 单读 {#dan-xiang-kong-jian-dan-du}