Skip to content

Commit

Permalink
feat(route): add 广东省食品药品审评认证技术协会 (DIYgod#13890)
Browse files Browse the repository at this point in the history
  • Loading branch information
nczitzk authored Nov 28, 2023
1 parent 683e415 commit 89ce36f
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
72 changes: 72 additions & 0 deletions lib/v2/gdsrx/index.js
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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/gdsrx/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/id?': ['nczitzk'],
};
61 changes: 61 additions & 0 deletions lib/v2/gdsrx/radar.js
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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/gdsrx/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:id?', require('./'));
};
18 changes: 18 additions & 0 deletions website/docs/routes/other.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,24 @@ Refer to [the list of supported currencies](https://wise.com/tools/exchange-rate

<Route author="Gem1ni" example="/guduodata/daily" path="/guduodata/daily" />

## 广东省食品药品审评认证技术协会 {#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui}

### 栏目 {#guang-dong-sheng-shi-pin-yao-pin-shen-ping-ren-zheng-ji-shu-xie-hui-lan-mu}

<Route author="nczitzk" example="/gdsrx" path="/gdsrx/:id?" paramsDesc={['栏目 id,可在对应栏目页 URL 中找到,见下表,默认为法规文库']} radar="1" rssbud="1">

| 栏目名称 | 栏目 id |
| ----------------- | ------- |
| 法规文库 | 10 |
| 法规资讯 | 12 |
| 专家供稿 | 13 |
| 协会动态 会员动态 | 20 |
| 协会动态 | 37 |
| 协会通知公告 | 38 |
| 会员动态 | 39 |

</Route>

## 国家留学网 {#guo-jia-liu-xue-wang}

### 通知 {#guo-jia-liu-xue-wang-tong-zhi}
Expand Down

0 comments on commit 89ce36f

Please sign in to comment.