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.
Merge pull request #2267 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
9 changed files
with
288 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const { id = '10' } = ctx.params; | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 15; | ||
|
||
const rootUrl = 'http://www.gdsrx.org.cn'; | ||
const currentUrl = new URL(`portal/list/index/id/${id}.html`, rootUrl).href; | ||
|
||
const { data: response } = await got(currentUrl); | ||
|
||
const $ = cheerio.load(response); | ||
|
||
let items = $('a.xn-item, a.t-item') | ||
.slice(0, limit) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.find('div.xn-d, div.t-e').text(), | ||
link: new URL(item.prop('href'), rootUrl).href, | ||
pubDate: parseDate(item.find('div.xn-time, div.t-f').text()), | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const { data: detailResponse } = await got(item.link); | ||
|
||
const content = cheerio.load(detailResponse); | ||
|
||
const categories = content('a.nav-a') | ||
.slice(1) | ||
.toArray() | ||
.map((c) => content(c).text()); | ||
|
||
item.title = categories.pop() || content('div.u-c').text(); | ||
item.description = content('div.u-f').html(); | ||
item.author = content('.author').text(); | ||
item.category = categories; | ||
item.pubDate = parseDate(content('div.u-d').text()); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const author = $('title').text(); | ||
const image = $('a.h-g img').prop('src'); | ||
const icon = new URL('favicon.ico', rootUrl).href; | ||
const subtitle = $('a.nav-a') | ||
.toArray() | ||
.map((c) => $(c).text()) | ||
.pop(); | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: `${author} - ${subtitle}`, | ||
link: currentUrl, | ||
description: $('meta[name="description"]').prop('content'), | ||
language: 'zh', | ||
image, | ||
icon, | ||
logo: icon, | ||
subtitle, | ||
author, | ||
}; | ||
}; |
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,61 @@ | ||
module.exports = { | ||
'gdsrx.org.cn': { | ||
_name: '广东省食品药品审评认证技术协会', | ||
'.': [ | ||
{ | ||
title: '栏目', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id'], | ||
target: (_, url) => { | ||
url = new URL(url); | ||
|
||
const idMatches = url.href.match(/\/id\/(\d+)\.html/); | ||
|
||
return `/gdsrx${idMatches ? `/${idMatches[1]}` : ''}`; | ||
}, | ||
}, | ||
{ | ||
title: '法规文库', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/10.html'], | ||
target: '/gdsrx/10', | ||
}, | ||
{ | ||
title: '法规资讯', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/12.html'], | ||
target: '/gdsrx/12', | ||
}, | ||
{ | ||
title: '专家供稿', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/13.html'], | ||
target: '/gdsrx/13', | ||
}, | ||
{ | ||
title: '协会动态 会员动态', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/20.html'], | ||
target: '/gdsrx/20', | ||
}, | ||
{ | ||
title: '协会动态', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/37.html'], | ||
target: '/gdsrx/37', | ||
}, | ||
{ | ||
title: '协会通知公告', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/38.html'], | ||
target: '/gdsrx/38', | ||
}, | ||
{ | ||
title: '会员动态', | ||
docs: 'https://docs.rsshub.app/routes/other#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu', | ||
source: ['/portal/list/index/id/39.html'], | ||
target: '/gdsrx/39', | ||
}, | ||
], | ||
}, | ||
}; |
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 = (router) => { | ||
router.get('/:id?', require('./')); | ||
}; |
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
Oops, something went wrong.