-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 衡阳日报 & 衡阳晚报 (#9418)
* feat(route): add 衡阳日报 & 衡阳晚报 * docs: update category
- Loading branch information
Ethan Shen
authored
Mar 30, 2022
1 parent
f3aa4c5
commit d88e52c
Showing
6 changed files
with
157 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
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,89 @@ | ||
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 type = ctx.params.type ?? 'hyrb'; | ||
const isDaily = type === 'hyrb'; | ||
|
||
const id = ctx.params.id; | ||
|
||
const rootUrl = 'http://epaper.hyqss.cn'; | ||
const currentUrl = `${rootUrl}${isDaily ? '' : `/${type}`}`; | ||
|
||
let response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
|
||
const url = response.data.match(/URL=(.*)"/)[1]; | ||
|
||
response = await got({ | ||
method: 'get', | ||
url: `${currentUrl}/${id ? url.replace(/node_\d+\.htm/, `node_19${isDaily ? '62' : '74'}${id}.htm`) : url}`, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
const matches = url.match(/html\/(.*)\/node/); | ||
const link = `${rootUrl}/${isDaily ? '' : 'hywb/'}html/${matches[1]}`; | ||
|
||
let items = $('#main-ed-articlenav-list') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((a) => `${link}/${$(a).attr('href')}`); | ||
|
||
if (!id) { | ||
await Promise.all( | ||
$('#bmdhTable') | ||
.find('#pageLink') | ||
.toArray() | ||
.map((p) => `${link}/${$(p).attr('href')}`) | ||
.map(async (p) => { | ||
const pageResponse = await got({ | ||
method: 'get', | ||
url: p, | ||
}); | ||
|
||
const page = cheerio.load(pageResponse.data); | ||
|
||
items.push( | ||
...page('#main-ed-articlenav-list') | ||
.first() | ||
.find('a') | ||
.toArray() | ||
.map((a) => `${link}/${page(a).attr('href')}`) | ||
); | ||
}) | ||
); | ||
} | ||
|
||
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: `衡阳${isDaily ? '日' : '晚'}报${id ? ` - ${$('strong').first().parent().text()}` : ''}`, | ||
link: currentUrl, | ||
item: items, | ||
allowEmpty: true, | ||
}; | ||
}; |
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,4 @@ | ||
module.exports = { | ||
'/hyrb/:id?': ['nczitzk'], | ||
'/hywb/: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,22 @@ | ||
const radars = [ | ||
{ | ||
title: '衡阳日报', | ||
docs: 'https://docs.rsshub.app/journal.html#heng-yang-quan-sou-suo-heng-yang-ri-bao', | ||
source: ['/'], | ||
target: '/hnrb/hyrb/:id?', | ||
}, | ||
{ | ||
title: '衡阳晚报', | ||
docs: 'https://docs.rsshub.app/journal.html#heng-yang-quan-sou-suo-heng-yang-wan-bao', | ||
source: ['/'], | ||
target: '/hnrb/hywb/:id?', | ||
}, | ||
]; | ||
|
||
module.exports = { | ||
'hyqss.cn': { | ||
_name: '衡阳全搜索', | ||
'.': radars, | ||
epaper: radars, | ||
}, | ||
}; |
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('/:type?/:id?', require('./index')); | ||
}; |