feat(route): add 晋江文学城作者最新作品 (#14499)

* feat(route): add 晋江文学城作者最新作品

* fix: add null check

* fix typo
This commit is contained in:
Ethan Shen
2024-02-20 22:56:29 +08:00
committed by GitHub
parent 5d5dc568f0
commit f95e5c3e9c
8 changed files with 293 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const { id } = ctx.params;
const rootUrl = 'https://www.jjwxc.net';
const currentUrl = new URL(`oneauthor.php?authorid=${id}`, rootUrl).href;
const { data: response } = await got(currentUrl, {
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response, 'gbk'));
const bookEl = $('font a').first();
const bookInfoEl = bookEl.parent();
const bookName = bookEl.text();
const bookUrl = new URL(bookEl.prop('href'), rootUrl).href;
const bookStatus = bookInfoEl.find('font').first().text();
const bookWords = bookInfoEl.find('font').eq(1).text();
const bookUpdatedTime = bookInfoEl.parent().contents().last().text().trim();
const bookId = bookUrl.split(/=/).pop();
const title = `${bookName}(${bookStatus}/${bookWords}/${bookUpdatedTime})`;
const author = $('span[itemprop="name"]').text();
const items = [
{
title,
link: bookUrl,
description: art(path.join(__dirname, 'templates/author.art'), {
bookName,
bookUrl,
bookStatus,
bookWords,
bookUpdatedTime,
}),
author,
category: [bookStatus],
guid: `jjwxc-${id}-${bookId}#${bookWords}`,
pubDate: timezone(parseDate(bookUpdatedTime), +8),
},
];
const logoEl = $('div.logo a img');
const image = `https:${logoEl.prop('src')}`;
const icon = new URL('favicon.ico', rootUrl).href;
ctx.state.data = {
item: items,
title: `${logoEl.prop('alt').replace(/logo/, '')} | ${author} - 最近更新`,
link: currentUrl,
description: $('span[itemprop="description"]').text(),
language: 'zh',
image,
icon,
logo: icon,
subtitle: $('meta[name="Description"]').prop('content'),
author,
};
};
+106
View File
@@ -0,0 +1,106 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const timezone = require('@/utils/timezone');
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 ? Number.parseInt(ctx.query.limit, 10) : 100;
const rootUrl = 'https://www.jjwxc.net';
const currentUrl = new URL(`onebook.php?novelid=${id}`, rootUrl).href;
const { data: response } = await got(currentUrl, {
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response, 'gbk'));
const author = $('meta[name="Author"]').prop('content');
const keywords = $('meta[name="Keywords"]').prop('content').split(/,/);
keywords.pop();
const category = keywords.pop();
let items = $('tr[itemprop="chapter"]')
.toArray()
.map((item) => {
item = $(item);
const chapterId = item.find('td').first().text().trim();
const chapterName = item.find('span[itemprop="headline"]').text().trim();
const chapterIntro = item.find('td').eq(2).text().trim();
const chapterUrl = new URL(`onebook.php?novelid=${id}&chapterid=${chapterId}`, rootUrl).href;
const chapterWords = item.find('td[itemprop="wordCount"]').text();
const chapterClicks = item.find('td.chapterclick').text();
const chapterUpdatedTime = item.find('td').last().text().trim();
const isVip = item.find('span[itemprop="headline"] font').last().text() === '[VIP]';
return {
title: `${chapterName} ${chapterIntro}`,
link: chapterUrl,
description: art(path.join(__dirname, 'templates/book.art'), {
chapterId,
chapterName,
chapterIntro,
chapterUrl,
chapterWords,
chapterClicks,
chapterUpdatedTime,
}),
author,
category: [isVip ? 'VIP' : undefined, ...(category?.split(/\s/) ?? [])].filter(Boolean),
guid: `jjwxc-${id}#${chapterId}`,
pubDate: timezone(parseDate(chapterUpdatedTime), +8),
isVip,
};
});
items.reverse();
items = await Promise.all(
items.slice(0, limit).map((item) =>
ctx.cache.tryGet(item.link, async () => {
if (!item.isVip) {
const { data: detailResponse } = await got(item.link, {
responseType: 'buffer',
});
const content = cheerio.load(iconv.decode(detailResponse, 'gbk'));
content('span.favorite_novel').parent().remove();
item.description += art(path.join(__dirname, 'templates/book.art'), {
description: content('div.novelbody').html(),
});
}
delete item.isVip;
return item;
})
)
);
const logoEl = $('div.logo a img');
const image = `https:${logoEl.prop('src')}`;
const icon = new URL('favicon.ico', rootUrl).href;
ctx.state.data = {
item: items,
title: `${logoEl.prop('alt').replace(/logo/, '')} | ${author}${keywords[0]}`,
link: currentUrl,
description: $('span[itemprop="description"]').text(),
language: 'zh',
image,
icon,
logo: icon,
subtitle: $('meta[name="Description"]').prop('content'),
author: $('meta[name="Author"]').prop('content'),
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/author/:id?': ['nczitzk'],
'/book/:id?': ['nczitzk'],
};
+29
View File
@@ -0,0 +1,29 @@
module.exports = {
'jjwxc.net': {
_name: '晋江文学城',
'.': [
{
title: '作者最新作品',
docs: 'https://docs.rsshub.app/routes/reading#jin-jiang-wen-xue-cheng-zuo-zhe-zui-xin-zuo-pin',
source: ['oneauthor.php'],
target: (_, url) => {
url = new URL(url);
const id = url.searchParams.get('authorid');
return `/jjwxc/author/${id}`;
},
},
{
title: '作品',
docs: 'https://docs.rsshub.app/routes/reading#jin-jiang-wen-xue-cheng-zuo-pin',
source: ['onebook.php'],
target: (_, url) => {
url = new URL(url);
const id = url.searchParams.get('novelid');
return `/jjwxc/book/${id}`;
},
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/author/:id?', require('./author'));
router.get('/book/:id?', require('./book'));
};
+28
View File
@@ -0,0 +1,28 @@
<table>
<tbody>
{{ if bookName }}
<tr>
<th>最近更新作品</th>
<td><a href="{{ bookUrl }}">{{ bookName }}</a></td>
</tr>
{{ /if }}
{{ if bookStatus }}
<tr>
<th>作品状态</th>
<td>{{ bookStatus }}</td>
</tr>
{{ /if }}
{{ if bookWords }}
<tr>
<th>作品字数</th>
<td>{{ bookWords }}</td>
</tr>
{{ /if }}
{{ if bookUpdatedTime }}
<tr>
<th>最后更新时间</th>
<td>{{ bookUpdatedTime }}</td>
</tr>
{{ /if }}
</tbody>
</table>
+44
View File
@@ -0,0 +1,44 @@
{{ if description }}
{{@ description }}
{{ else }}
<table>
<tbody>
{{ if chapterId }}
<tr>
<th>章节</th>
<td><a href="{{ chapterUrl }}">{{ chapterId }}</a></td>
</tr>
{{ /if }}
{{ if chapterName }}
<tr>
<th>标题</th>
<td><a href="{{ chapterUrl }}">{{ chapterName }}</a></td>
</tr>
{{ /if }}
{{ if chapterIntro }}
<tr>
<th>内容提要</th>
<td><a href="{{ chapterUrl }}">{{ chapterIntro }}</a></td>
</tr>
{{ /if }}
{{ if chapterWords }}
<tr>
<th>字数</th>
<td>{{ chapterWords }}</td>
</tr>
{{ /if }}
{{ if chapterClicks }}
<tr>
<th>点击</th>
<td>{{ chapterClicks }}</td>
</tr>
{{ /if }}
{{ if chapterUpdatedTime }}
<tr>
<th>更新时间</th>
<td>{{ chapterUpdatedTime }}</td>
</tr>
{{ /if }}
</tbody>
</table>
{{ /if }}
+10
View File
@@ -242,6 +242,16 @@
<Route author="junbaor" example="/enclavebooks/collection/103702" path="/enclavebooks/collection/:uid" paramsDesc={['用户ID, 自行抓包寻找']} />
## 晋江文学城 {#jin-jiang-wen-xue-cheng}
### 作者最新作品 {#jin-jiang-wen-xue-cheng-zuo-zhe-zui-xin-zuo-pin}
<Route author="nczitzk" example="/jjwxc/author/4364484" path="/jjwxc/author/:id?" paramsDesc={['作者 id,可在对应作者页中找到']} radar="1" />
### 作品 {#jin-jiang-wen-xue-cheng-zuo-pin}
<Route author="nczitzk" example="/jjwxc/book/7013024" path="/jjwxc/book/:id?" paramsDesc={['作品 id,可在对应作品页中找到']} radar="1" />
## 禁忌书屋 {#jin-ji-shu-wu}
### 首页 {#jin-ji-shu-wu-shou-ye}