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#12058)
* feat(route): add 浙江在线浙报集团系列报刊 * fix: duplicated content in jnyb
- Loading branch information
Showing
5 changed files
with
167 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
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,3 @@ | ||
module.exports = { | ||
'/paper/:id?': ['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,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, | ||
}; | ||
}; |
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,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', | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = function (router) { | ||
router.get('/paper/:id?', require('./paper')); | ||
}; |