Skip to content

Commit

Permalink
Merge pull request #2267 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Nov 28, 2023
2 parents c0def92 + 89ce36f commit c5e4a99
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 170 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('./'));
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"@koa/router": "12.0.1",
"@notionhq/client": "2.2.13",
"@postlight/parser": "2.2.3",
"@sentry/node": "7.81.1",
"@tonyrl/rand-user-agent": "2.0.40",
"@sentry/node": "7.82.0",
"@tonyrl/rand-user-agent": "2.0.41",
"aes-js": "3.1.2",
"art-template": "4.13.2",
"bbcodejs": "0.0.4",
Expand All @@ -112,10 +112,10 @@
"ioredis": "5.3.2",
"ip-regex": "4.3.0",
"is-localhost-ip": "2.0.0",
"jsdom": "22.1.0",
"jsdom": "23.0.0",
"json-bigint": "1.0.0",
"json5": "2.2.3",
"jsrsasign": "10.8.6",
"jsrsasign": "10.9.0",
"koa": "2.14.2",
"koa-basic-auth": "4.0.0",
"koa-favicon": "2.1.0",
Expand Down Expand Up @@ -193,7 +193,7 @@
"jest-junit": "16.0.0",
"lint-staged": "15.1.0",
"mockdate": "3.0.5",
"nock": "13.3.8",
"nock": "13.4.0",
"nodemon": "3.0.1",
"prettier": "3.1.0",
"remark": "13.0.0",
Expand Down
Loading

0 comments on commit c5e4a99

Please sign in to comment.