Skip to content

Commit

Permalink
feat(route): add 刺猬猫 (DIYgod#14592)
Browse files Browse the repository at this point in the history
* add 刺猬猫

* fix getting chapter content

* add docs & radar; fix image

* update default limit

* do not fetch chapter content if chapter is locked
  • Loading branch information
keocheung authored Feb 29, 2024
1 parent cbbd829 commit 645e6c0
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/v2/ciweimao/chapter.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/ciweimao/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/chapter/:id': ['keocheung'],
};
13 changes: 13 additions & 0 deletions lib/v2/ciweimao/radar.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/ciweimao/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/chapter/:id', require('./chapter'));
};
6 changes: 6 additions & 0 deletions website/docs/routes/reading.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 645e6c0

Please sign in to comment.