Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 浙江在线浙报集团系列报刊 #12058

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,18 @@ category 对应的关键词有

</Route>

## 浙江在线

### 浙报集团系列报刊

<Route author="nczitzk" example="/zjol/paper/zjrb" path="/zjol/paper/:id?" :paramsDesc="['报纸 id,见下表,默认为 `zjrb`,即浙江日报']">

| 浙江日报 | 钱江晚报 | 美术报 | 浙江老年报 | 浙江法制报 | 江南游报 |
| ---- | ---- | --- | ----- | ----- | ---- |
| zjrb | qjwb | msb | zjlnb | zjfzb | jnyb |

</Route>

## 中国日报

### 英语点津
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/zjol/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/paper/:id?': ['nczitzk'],
};
85 changes: 85 additions & 0 deletions lib/v2/zjol/paper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const id = ctx.params.id ?? 'zjrb';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 100;

const query = id === 'jnyb' ? 'map[name="PagePicMap"] area' : 'ul.main-ed-articlenav-list li a';

const rootUrl = id === 'qjwb' ? 'http://qjwb.thehour.cn' : `https://${id}.zjol.com.cn`;
let currentUrl = `${rootUrl}/paperindex.htm`;

let response = await got({
method: 'get',
url: currentUrl,
});

const url = response.data.match(/URL=(.*)"/)[1];
const pubDate = parseDate(url.match(/(\d{4}-\d{2}\/\d{2})/)[1], 'YYYY-MM/DD');

currentUrl = `${rootUrl}/${url.replace(`/${url.split('/').pop()}`, '')}`;

response = await got({
method: 'get',
url: `${rootUrl}/${url}`,
});

const $ = cheerio.load(response.data);

let items = $(query)
.toArray()
.map((a) => `${currentUrl}/${$(a).attr('href').split('?')[0]}`);

await Promise.all(
$('#pageLink')
.slice(1)
.toArray()
.map((p) => `${currentUrl}/${$(p).attr('href')}`)
.map(async (p) => {
const pageResponse = await got({
method: 'get',
url: p,
});

const page = cheerio.load(pageResponse.data);

items.push(
...page(query)
.toArray()
.map((a) => `${currentUrl}/${page(a).attr('href').split('?')[0]}`)
);
})
);

items = await Promise.all(
items.slice(0, limit).map((link) =>
ctx.cache.tryGet(link, async () => {
const detailResponse = await got({
method: 'get',
url: link,
});

const content = cheerio.load(detailResponse.data);

const title = content('.main-article-title').text();

content('.main-article-alltitle').remove();

return {
link,
title,
pubDate,
description: content('.main-article-content').html(),
};
})
)
);

ctx.state.data = {
title: $('title').text(),
link: rootUrl,
item: items,
};
};
61 changes: 61 additions & 0 deletions lib/v2/zjol/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module.exports = {
'zjol.com.cn': {
_name: '浙江在线',
'.': [
{
title: '浙报集团系列报刊',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: (params, url) => `/zjol/paper/${new URL(url).toString().match(/\/\/(.*?)\.zjol/)[1]}`,
},
],
zjrb: [
{
title: '浙江日报',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: '/zjol/paper/zjrb',
},
],
qjwb: [
{
title: '钱江晚报',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: '/zjol/paper/qjwb',
},
],
msb: [
{
title: '美术报',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: '/zjol/paper/msb',
},
],
zjlnb: [
{
title: '浙江老年报',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: '/zjol/paper/zjlnb',
},
],
zjfzb: [
{
title: '浙江法制报',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: '/zjol/paper/zjfzb',
},
],
jnyb: [
{
title: '江南游报',
docs: 'https://docs.rsshub.app/traditional-media.html#zhe-jiang-zai-xian-zhe-bao-ji-tuan-xi-lie-bao-kan',
source: ['/'],
target: '/zjol/paper/jnyb',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/zjol/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/paper/:id?', require('./paper'));
};