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 湖南日报 * docs: update category * update docs/traditional-media.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
125 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,85 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const timezone = require('@/utils/timezone'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const id = ctx.params.id; | ||
|
||
const rootUrl = 'https://hnrb.voc.com.cn'; | ||
const currentUrl = `${rootUrl}/hnrb_epaper`; | ||
|
||
let response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
|
||
response = await got({ | ||
method: 'get', | ||
url: `${currentUrl}/${id ? response.data.match(/URL=(.*)"/)[1].replace(/node_\d+\.htm$/, `node_20${id}.htm`) : response.data.match(/URL=(.*)"/)[1]}`, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
const matches = response.data.match(/images\/(\d{4}-\d{2}\/\d{2})\/\d{2}\/\d+_brief/); | ||
const link = `${rootUrl}/hnrb_epaper/html/${matches[1]}`; | ||
|
||
let items = $('tbody') | ||
.eq(1) | ||
.find('a') | ||
.toArray() | ||
.map((a) => `${link}/${$(a).attr('href').replace(/\.\//, '')}`) | ||
.filter((a) => /div=-1$/.test(a)); | ||
|
||
if (!id) { | ||
await Promise.all( | ||
$('#pageLink') | ||
.slice(1) | ||
.toArray() | ||
.map((p) => `${link}/${$(p).attr('href').replace(/\.\//, '')}`) | ||
.map(async (p) => { | ||
const pageResponse = await got({ | ||
method: 'get', | ||
url: p, | ||
}); | ||
|
||
const page = cheerio.load(pageResponse.data); | ||
|
||
items.push( | ||
...page('tbody') | ||
.eq(1) | ||
.find('a') | ||
.toArray() | ||
.map((a) => `${link}/${page(a).attr('href').replace(/\.\//, '')}`) | ||
.filter((a) => /div=-1$/.test(a)) | ||
); | ||
}) | ||
); | ||
} | ||
|
||
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('.font01').text(), | ||
description: content('#ozoom').html(), | ||
pubDate: timezone(parseDate(matches[1], 'YYYY-MM/DD'), +8), | ||
}; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `湖南日报${id ? ` - ${$('strong').first().parent().text()}` : ''}`, | ||
link: currentUrl, | ||
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,3 @@ | ||
module.exports = { | ||
'/: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,13 @@ | ||
module.exports = { | ||
'voc.com.cn': { | ||
_name: '华声在线', | ||
'.': [ | ||
{ | ||
title: '湖南日报', | ||
docs: 'https://docs.rsshub.app/journal.html#hu-nan-ri-bao-dian-zi-kan-wu', | ||
source: ['/'], | ||
target: '/hnrb/:id', | ||
}, | ||
], | ||
}, | ||
}; |
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('/:id?', require('./index')); | ||
}; |