forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 明月中文网 (DIYgod#14520)
* feat(route): add 明月中文网 * fix: remove 404 items
- Loading branch information
Showing
8 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { rootUrl, fetchItems } = require('./util'); | ||
|
||
module.exports = async (ctx) => { | ||
const { category = '1_1' } = ctx.params; | ||
const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30; | ||
|
||
const currentUrl = new URL(`class/${category}.html`, rootUrl).href; | ||
|
||
ctx.state.data = await fetchItems(limit, currentUrl, ctx.cache.tryGet); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'/class/:category?': ['nczitzk'], | ||
'/top/:category?': ['nczitzk'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module.exports = { | ||
'56kog.com': { | ||
_name: '明月中文网', | ||
'.': [ | ||
{ | ||
title: '玄幻魔法', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/1_1.html'], | ||
target: '/56kog/class/1_1', | ||
}, | ||
{ | ||
title: '武侠修真', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/2_1.html'], | ||
target: '/56kog/class/2_1', | ||
}, | ||
{ | ||
title: '历史军事', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/4_1.html'], | ||
target: '/56kog/class/4_1', | ||
}, | ||
{ | ||
title: '侦探推理', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/5_1.html'], | ||
target: '/56kog/class/5_1', | ||
}, | ||
{ | ||
title: '网游动漫', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/6_1.html'], | ||
target: '/56kog/class/6_1', | ||
}, | ||
{ | ||
title: '恐怖灵异', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/8_1.html'], | ||
target: '/56kog/class/8_1', | ||
}, | ||
{ | ||
title: '都市言情', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/3_1.html'], | ||
target: '/56kog/class/3_1', | ||
}, | ||
{ | ||
title: '科幻', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/7_1.html'], | ||
target: '/56kog/class/7_1', | ||
}, | ||
{ | ||
title: '女生小说', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/9_1.html'], | ||
target: '/56kog/class/9_1', | ||
}, | ||
{ | ||
title: '其他', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-fen-lei', | ||
source: ['/class/10_1.html'], | ||
target: '/56kog/class/10_1', | ||
}, | ||
{ | ||
title: '周点击榜', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-bang-dan', | ||
source: ['/top/weekvisit_1.html'], | ||
target: '/56kog/top/weekvisit', | ||
}, | ||
{ | ||
title: '总收藏榜', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-bang-dan', | ||
source: ['/top/goodnum_1.html'], | ||
target: '/56kog/top/goodnum', | ||
}, | ||
{ | ||
title: '最新入库', | ||
docs: 'https://docs.rsshub.app/routes/reading#ming-yue-zhong-wen-wang-bang-dan', | ||
source: ['/top/postdate_1.html'], | ||
target: '/56kog/top/postdate', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = (router) => { | ||
router.get('/class/:category?', require('./class')); | ||
router.get('/top/:category?', require('./top')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{ if images }} | ||
{{ each images image }} | ||
{{ if image?.src }} | ||
<figure> | ||
<img | ||
{{ if image.alt }} | ||
alt="{{ image.alt }}" | ||
{{ /if }} | ||
src="{{ image.src }}"> | ||
</figure> | ||
{{ /if }} | ||
{{ /each }} | ||
{{ /if }} | ||
|
||
{{ if details }} | ||
<table> | ||
<tbody> | ||
{{ each details detail }} | ||
<tr> | ||
<th>{{ detail.label }}</th> | ||
<td> | ||
{{ if detail.value?.href && detail.value?.text }} | ||
<a href="{{ detail.value.href }}">{{ detail.value.text }}</a> | ||
{{ else }} | ||
{{ detail.value }} | ||
{{ /if }} | ||
</td> | ||
</tr> | ||
{{ /each }} | ||
</tbody> | ||
</table> | ||
{{ /if }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { rootUrl, fetchItems } = require('./util'); | ||
|
||
module.exports = async (ctx) => { | ||
const { category = 'weekvisit' } = ctx.params; | ||
const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30; | ||
|
||
const currentUrl = new URL(`top/${category.split(/_/)[0]}_1.html`, rootUrl).href; | ||
|
||
ctx.state.data = await fetchItems(limit, currentUrl, ctx.cache.tryGet); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
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'); | ||
|
||
const rootUrl = 'https://www.56kog.com'; | ||
|
||
const fetchItems = async (limit, currentUrl, tryGet) => { | ||
const { data: response } = await got(currentUrl, { | ||
responseType: 'buffer', | ||
}); | ||
|
||
const $ = cheerio.load(iconv.decode(response, 'gbk')); | ||
|
||
let items = $('p.line') | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
const a = item.find('a'); | ||
|
||
return { | ||
title: a.text(), | ||
link: new URL(a.prop('href'), rootUrl).href, | ||
author: item.find('span').last().text(), | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
tryGet(item.link, async () => { | ||
try { | ||
const { data: detailResponse } = await got(item.link, { | ||
responseType: 'buffer', | ||
}); | ||
|
||
const content = cheerio.load(iconv.decode(detailResponse, 'gbk')); | ||
|
||
const details = content('div.mohe-content p') | ||
.toArray() | ||
.map((detail) => { | ||
detail = content(detail); | ||
const as = detail.find('a'); | ||
|
||
return { | ||
label: detail.find('span.c-l-depths').text().split(/:/)[0], | ||
value: | ||
as.length === 0 | ||
? content( | ||
detail | ||
.contents() | ||
.toArray() | ||
.find((c) => c.nodeType === 3) | ||
) | ||
.text() | ||
.trim() | ||
: { | ||
href: new URL(as.first().prop('href'), rootUrl).href, | ||
text: as.first().text().trim(), | ||
}, | ||
}; | ||
}); | ||
|
||
const pubDate = details.find((detail) => detail.label === '更新').value; | ||
|
||
item.title = content('h1').contents().first().text(); | ||
item.description = art(path.join(__dirname, 'templates/description.art'), { | ||
images: [ | ||
{ | ||
src: new URL(content('a.mohe-imgs img').prop('src'), rootUrl).href, | ||
alt: item.title, | ||
}, | ||
], | ||
details, | ||
}); | ||
item.author = details.find((detail) => detail.label === '作者').value; | ||
item.category = [details.find((detail) => detail.label === '状态').value, details.find((detail) => detail.label === '类型').value.text].filter(Boolean); | ||
item.guid = `56kog-${item.link.match(/\/(\d+)\.html$/)[1]}#${pubDate}`; | ||
item.pubDate = timezone(parseDate(pubDate), +8); | ||
} catch { | ||
// no-empty | ||
} | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const icon = new URL('favicon.ico', rootUrl).href; | ||
|
||
return { | ||
item: items.filter((item) => item.description).slice(0, limit), | ||
title: $('title').text(), | ||
link: currentUrl, | ||
description: $('meta[name="description"]').prop('content'), | ||
language: $('html').prop('lang'), | ||
icon, | ||
logo: icon, | ||
subtitle: $('meta[name="keywords"]').prop('content'), | ||
author: $('div.uni_footer a').text(), | ||
allowEmpty: true, | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
rootUrl, | ||
fetchItems, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters