From 8a6f750f8ba1a338a52578bf9cff64e63fe9aa8a Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Sun, 30 Jul 2023 05:46:33 +0800
Subject: [PATCH] feat(route): add Rawkuma (#12901)
* feat(route): add Rawkuma
* update lib/v2/rawkuma/manga.js
* fix: eslint
---------
---
docs/anime.md | 6 ++
docs/en/anime.md | 6 ++
lib/v2/rawkuma/maintainer.js | 3 +
lib/v2/rawkuma/manga.js | 81 ++++++++++++++++++++++++
lib/v2/rawkuma/radar.js | 13 ++++
lib/v2/rawkuma/router.js | 3 +
lib/v2/rawkuma/templates/description.art | 3 +
7 files changed, 115 insertions(+)
create mode 100644 lib/v2/rawkuma/maintainer.js
create mode 100644 lib/v2/rawkuma/manga.js
create mode 100644 lib/v2/rawkuma/radar.js
create mode 100644 lib/v2/rawkuma/router.js
create mode 100644 lib/v2/rawkuma/templates/description.art
diff --git a/docs/anime.md b/docs/anime.md
index e5c78b45c..15e6894e7 100644
--- a/docs/anime.md
+++ b/docs/anime.md
@@ -460,6 +460,12 @@ Sources
+## Rawkuma
+
+### Manga
+
+
+
## say 花火
### 文章
diff --git a/docs/en/anime.md b/docs/en/anime.md
index 74269e150..ed92164bd 100644
--- a/docs/en/anime.md
+++ b/docs/en/anime.md
@@ -222,6 +222,12 @@ The RSS routing has not been rigorously tested and the information provided cann
+## Rawkuma
+
+### Manga
+
+
+
## THBWiki
### Calendar
diff --git a/lib/v2/rawkuma/maintainer.js b/lib/v2/rawkuma/maintainer.js
new file mode 100644
index 000000000..65a7b4134
--- /dev/null
+++ b/lib/v2/rawkuma/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/manga/:id': ['nczitzk'],
+};
diff --git a/lib/v2/rawkuma/manga.js b/lib/v2/rawkuma/manga.js
new file mode 100644
index 000000000..28a7b5fd0
--- /dev/null
+++ b/lib/v2/rawkuma/manga.js
@@ -0,0 +1,81 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const { parseDate } = require('@/utils/parse-date');
+const { art } = require('@/utils/render');
+const path = require('path');
+
+module.exports = async (ctx) => {
+ const { id } = ctx.params;
+ const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 50;
+
+ const rootUrl = 'https://rawkuma.com';
+ const currentUrl = new URL(`/manga/${id}`, rootUrl).href;
+
+ const { data: response } = await got(currentUrl);
+
+ const $ = cheerio.load(response);
+
+ const author = $('div.fmed span').eq(1).text().trim();
+ const category = $('div.wd-full span.mgen a[rel="tag"]')
+ .toArray()
+ .map((c) => $(c).text());
+
+ let items = $('div.eph-num')
+ .slice(0, limit)
+ .toArray()
+ .map((item) => {
+ item = $(item);
+
+ return {
+ title: item.find('span.chapternum').text(),
+ link: item.find('a').prop('href'),
+ author,
+ category,
+ pubDate: parseDate(item.find('span.chapterdate').text(), 'MMMM DD'),
+ enclosure_url: item.next().find('a.dload').prop('href'),
+ enclosure_type: 'application/zip',
+ };
+ });
+
+ items = await Promise.all(
+ items.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const { data: detailResponse } = await got(item.link);
+
+ const content = cheerio.load(detailResponse);
+
+ const imageMatches = detailResponse.match(/"images":(\[.*?\])\}\],"lazyload"/);
+
+ const images = imageMatches ? JSON.parse(imageMatches[1]) : [];
+
+ item.title = content('div.chpnw').text().trim();
+ item.description = art(path.join(__dirname, 'templates/description.art'), {
+ images,
+ });
+ item.author = author;
+ item.category = category;
+ item.pubDate = parseDate(content('time.entry-date').prop('datetime').replace(/WIB/, 'T'));
+ item.enclosure_url = content('span.dlx a').prop('href');
+ item.enclosure_type = 'application/zip';
+
+ return item;
+ })
+ )
+ );
+
+ const icon = $('link[rel="apple-touch-icon"]')
+ .prop('href')
+ .replace(/-\d+x\d+/, '');
+
+ ctx.state.data = {
+ item: items,
+ title: $('title').text(),
+ link: currentUrl,
+ description: $('div[itemprop="description"]').text(),
+ image: $('meta[property="og:image"]').prop('content'),
+ icon,
+ logo: icon,
+ subtitle: $('div.wd-full span').text(),
+ author,
+ };
+};
diff --git a/lib/v2/rawkuma/radar.js b/lib/v2/rawkuma/radar.js
new file mode 100644
index 000000000..02b461a4c
--- /dev/null
+++ b/lib/v2/rawkuma/radar.js
@@ -0,0 +1,13 @@
+module.exports = {
+ 'rawkuma.com': {
+ _name: 'Rawkuma',
+ '.': [
+ {
+ title: 'Manga',
+ docs: 'https://docs.rsshub.app/anime.html#rawkuma-manga',
+ source: ['/manga/:id', '/'],
+ target: '/rawkuma/manga/:id',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/rawkuma/router.js b/lib/v2/rawkuma/router.js
new file mode 100644
index 000000000..1c34fa924
--- /dev/null
+++ b/lib/v2/rawkuma/router.js
@@ -0,0 +1,3 @@
+module.exports = function (router) {
+ router.get('/manga/:id', require('./manga'));
+};
diff --git a/lib/v2/rawkuma/templates/description.art b/lib/v2/rawkuma/templates/description.art
new file mode 100644
index 000000000..53c7f7b39
--- /dev/null
+++ b/lib/v2/rawkuma/templates/description.art
@@ -0,0 +1,3 @@
+{{ each images image }}
+
+{{ /each }}
\ No newline at end of file