Skip to content

Commit

Permalink
feat(route): add 浙江在线浙报集团系列报刊 (DIYgod#12058)
Browse files Browse the repository at this point in the history
* feat(route): add 浙江在线浙报集团系列报刊

* fix: duplicated content in jnyb
  • Loading branch information
nczitzk authored Mar 8, 2023
1 parent fdb1e21 commit 197610d
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
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'],
};
88 changes: 88 additions & 0 deletions lib/v2/zjol/paper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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')}`);

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')}`)
);
})
);

items = await Promise.all(
items
.filter((a) => (id === 'jnyb' ? /\?div=1$/.test(a) : true))
.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 {
title,
pubDate,
link: link.split('?')[0],
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'));
};

0 comments on commit 197610d

Please sign in to comment.