diff --git a/docs/en/reading.md b/docs/en/reading.md index 6226d1835..401d5c189 100644 --- a/docs/en/reading.md +++ b/docs/en/reading.md @@ -10,6 +10,16 @@ pageClass: routes +## kakuyomu + +### episode + + + +Eg: + + + ## Literotica ### New Stories diff --git a/docs/reading.md b/docs/reading.md index ebbbd0683..e4a10936b 100644 --- a/docs/reading.md +++ b/docs/reading.md @@ -10,6 +10,16 @@ pageClass: routes +## kakuyomu + +### 章节更新 + + + +举例网址: + + + ## Kindle Unlimited ### 会员限时免费读书单 diff --git a/lib/v2/kakuyomu/episode.js b/lib/v2/kakuyomu/episode.js new file mode 100644 index 000000000..383fd4b6b --- /dev/null +++ b/lib/v2/kakuyomu/episode.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 id = ctx.params.id; + const limit = parseInt(ctx.query.limit) || 5; + const work_url = `https://kakuyomu.jp/works/${id}`; + const $ = cheerio.load(await get(work_url)); + + const work_title = $('#workTitle').text(); + const introduction = $('#introduction').text(); + + const episode_list = $('a.widget-toc-episode-episodeTitle') + .map((_, episode) => { + const $_episode = $(episode); + return { + title: $_episode.find('span').text(), + link: $_episode.attr('href'), + pubDate: parseDate($_episode.find('time').attr('datetime')), + }; + }) + .toArray() + .sort((a, b) => (a.pubDate <= b.pubDate ? 1 : -1)) + .slice(0, limit); + + const item_list = await Promise.all( + episode_list.map((episode) => + ctx.cache.tryGet(episode.link, async () => { + episode.link = `https://kakuyomu.jp${episode.link}`; + const content = cheerio.load(await get(episode.link)); + episode.description = content('.widget-episodeBody').html(); + return episode; + }) + ) + ); + + ctx.state.data = { + title: work_title, + link: work_url, + description: introduction, + language: 'ja', + item: item_list, + }; +}; + +const get = async (url) => { + const response = await got({ + method: 'get', + url, + }); + + return response.data; +}; diff --git a/lib/v2/kakuyomu/maintainer.js b/lib/v2/kakuyomu/maintainer.js new file mode 100644 index 000000000..ee25bceb5 --- /dev/null +++ b/lib/v2/kakuyomu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/episode/:id': ['huangliangshusheng'], +}; diff --git a/lib/v2/kakuyomu/radar.js b/lib/v2/kakuyomu/radar.js new file mode 100644 index 000000000..a49a6f500 --- /dev/null +++ b/lib/v2/kakuyomu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'kakuyomu.jp': { + _name: 'kakuyomu', + '.': [ + { + title: '章节更新', + docs: 'https://docs.rsshub.app/reading.html#kakuyomu-zhang-jie-geng-xin', + source: ['/works/:id'], + target: '/kakuyomu/episode/:id', + }, + ], + }, +}; diff --git a/lib/v2/kakuyomu/router.js b/lib/v2/kakuyomu/router.js new file mode 100644 index 000000000..23c9c2865 --- /dev/null +++ b/lib/v2/kakuyomu/router.js @@ -0,0 +1 @@ +module.exports = (router) => router.get('/episode/:id', require('./episode.js'));