feat(route): 嘉兴日报 & 南湖晚报 (#9979)

This commit is contained in:
Ethan Shen
2022-06-18 12:45:11 +09:00
committed by GitHub
parent e6ab7dde96
commit 31aaf4ed0d
6 changed files with 172 additions and 0 deletions
+50
View File
@@ -1278,6 +1278,56 @@ category 对应的关键词有
</Route>
## 南湖清风
### 嘉兴日报
<Route author="nczitzk" example="/cnjxol/jxrb" path="/cnjxol/jxrb/:id?" :paramsDesc="['编号,见下表,默认为全部']" anticrawler="1">
| 版 | 编号 |
| ------------ | -- |
| 全部 | |
| 第 01 版:要闻 | 01 |
| 第 02 版:要闻 | 02 |
| 第 03 版:要闻 | 03 |
| 第 04 版:嘉一度 | 04 |
| 第 05 版:聚焦 | 05 |
| 第 06 版:党报热线 | 06 |
| 第 07 版:天下 | 07 |
| 第 08 版:聚焦 | 08 |
| 第 09 版:南湖新闻 | 09 |
| 第 10 版:综合 | 10 |
| 第 11 版:梅花洲 | 11 |
| 第 12 版:南湖纵横 | 12 |
| 第 13 版:秀洲新闻 | 13 |
| 第 14 版:综合 | 14 |
| 第 15 版:秀・观察 | 15 |
| 第 16 版:走进高新区 | 16 |
</Route>
### 南湖晚报
<Route author="nczitzk" example="/cnjxol/nhwb" path="/cnjxol/nhwb/:id?" :paramsDesc="['编号,见下表,默认为全部']" anticrawler="1">
| 版 | 编号 |
| -------------------- | -- |
| 全部 | |
| 第 01 版:要闻 | 01 |
| 第 02 版:品质嘉兴・红船旁的美丽城镇 | 02 |
| 第 03 版:嘉兴新闻 | 03 |
| 第 04 版:嘉兴新闻 | 04 |
| 第 05 版:今日聚焦 | 05 |
| 第 06 版:嘉兴新闻 | 06 |
| 第 07 版:热线新闻 | 07 |
| 第 08 版:财经新闻 | 08 |
| 第 09 版:热线新闻 | 09 |
| 第 10 版:公益广告 | 10 |
| 第 11 版:消费周刊 | 11 |
| 第 12 版:悦读坊 | 12 |
</Route>
## 南华早报 SCMP
### 新闻
+94
View File
@@ -0,0 +1,94 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const categories = {
jxrb: '嘉兴日报',
nhwb: '南湖晚报',
};
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'jxrb';
const id = ctx.params.id;
const rootUrl = `https://${category}.cnjxol.com`;
const currentUrl = `${rootUrl}/${category}Paper/pc/layout`;
const response = await got({
method: 'get',
url: currentUrl,
});
let $ = cheerio.load(response.data);
const dateMatch = $('a')
.first()
.attr('href')
.match(/\d{6}\/\d{2}/)[0];
let items = [];
if (id) {
const pageUrl = `${currentUrl}/${dateMatch}/node_${id}.html`;
const pageResponse = await got({
method: 'get',
url: pageUrl,
});
$ = cheerio.load(pageResponse.data);
items = $('#articlelist .clearfix a')
.toArray()
.map((a) => `${currentUrl}/${$(a).attr('href')}`.replace(/layout\/\.\.\/\.\.\/\.\.\//g, ''));
} else {
await Promise.all(
$('#list li a')
.toArray()
.map(async (p) => {
const pageResponse = await got({
method: 'get',
url: `${currentUrl}/${$(p).attr('href')}`,
});
const page = cheerio.load(pageResponse.data);
items.push(
...page('#articlelist .clearfix a')
.toArray()
.map((a) => `${currentUrl}/${page(a).attr('href')}`.replace(/layout\/\.\.\/\.\.\/\.\.\//g, ''))
);
})
);
}
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item, async () => {
const detailResponse = await got({
method: 'get',
url: item,
});
const content = cheerio.load(detailResponse.data);
return {
link: item,
title: content('#Title').text(),
pubDate: parseDate(content('date').text()),
description: art(path.join(__dirname, 'templates/description.art'), {
attachment: content('.attachment').html(),
content: content('founder-content').html(),
}),
};
})
)
);
ctx.state.data = {
title: `${categories[category]}${id ? ` - ${$('#layout').text()}` : ''}`,
link: currentUrl,
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/jxrb/:id?': ['nczitzk'],
'/nhwb/:id?': ['nczitzk'],
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'cnjxol.com': {
_name: '南湖清风',
'.': [
{
title: '嘉兴日报',
docs: 'https://docs.rsshub.app/traditional-media.html#nan-hu-qing-feng-jia-xing-ri-bao',
source: ['/'],
target: '/cnjxol/jxrb/:id',
},
{
title: '南湖晚报',
docs: 'https://docs.rsshub.app/traditional-media.html#nan-hu-qing-feng-nan-hu-wan-bao',
source: ['/'],
target: '/cnjxol/nhwb/:id',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:category?/:id?', require('./index'));
};
+2
View File
@@ -0,0 +1,2 @@
{{@ attachment }}
{{@ content }}