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 中国钢铁工业协会 (DIYgod#13541)
* chore(deps-dev): bump @tsconfig/docusaurus in /website (DIYgod#686) Bumps [@tsconfig/docusaurus](https://github.com/tsconfig/bases/tree/HEAD/bases) from 2.0.1 to 2.0.2. - [Commits](https://github.com/tsconfig/bases/commits/HEAD/bases) --- updated-dependencies: - dependency-name: "@tsconfig/docusaurus" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(route): add 中国钢铁工业协会 * fix typo * fix docs * docs: fix heading --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
363b1b6
commit b91e9c2
Showing
5 changed files
with
269 additions
and
13 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,83 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const { id = '58af05dfb6b4300151760176d2aad0a04c275aaadbb1315039263f021f920dcd' } = ctx.params; | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 15; | ||
|
||
const rootUrl = 'https://www.chinaisa.org.cn'; | ||
|
||
const apiUrl = new URL('gxportal/xfpt/portal/getColumnList', rootUrl).href; | ||
const apiArticleUrl = new URL('gxportal/xfpt/portal/viewArticleById', rootUrl).href; | ||
const currentUrl = new URL(`gxportal/xfgl/portal/list.html?columnId=${id}`, rootUrl).href; | ||
|
||
const { data: response } = await got.post(apiUrl, { | ||
form: { | ||
params: encodeURI(`{"columnId":"${id}"}`), | ||
}, | ||
}); | ||
|
||
let $ = cheerio.load(response.articleListHtml); | ||
|
||
let items = $('ul.list li a') | ||
.slice(0, limit) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
|
||
return { | ||
title: item.prop('title') ?? item.text(), | ||
link: new URL(`gxportal/xfgl/portal/${item.prop('href')}`, rootUrl).href, | ||
guid: item.prop('href').match(/articleId=(\w+)/)[1], | ||
pubDate: parseDate(item.parent().find('span.times').text().replace(/\[|\]/g, '')), | ||
}; | ||
}); | ||
|
||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const { data: detailResponse } = await got.post(apiArticleUrl, { | ||
form: { | ||
params: encodeURI(`{"articleId":"${item.guid}","columnId":"${id}"}`), | ||
}, | ||
}); | ||
|
||
const articleContent = detailResponse.article_content; | ||
|
||
const content = cheerio.load(articleContent); | ||
|
||
const matches = articleContent.match(/文章来源:(.*?)日期:(\d+-\d+-\d+)/); | ||
|
||
item.title = content('div.article_title').contents().first().text() || item.title; | ||
item.description = content('div.article_main').html(); | ||
item.author = matches[1].split(/&/)[0]; | ||
item.guid = `chinaisa-${item.guid}`; | ||
item.pubDate = parseDate(matches[2]); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const subtitle = $('div.head-tit').text(); | ||
|
||
const { data: currentResponse } = await got(currentUrl); | ||
|
||
$ = cheerio.load(currentResponse); | ||
|
||
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href; | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: `${$('title').text()} - ${subtitle}`, | ||
link: currentUrl, | ||
description: $('meta[name="description"]').prop('content'), | ||
language: 'cn', | ||
image: new URL('img/logo.jpg', rootUrl).href, | ||
icon, | ||
logo: icon, | ||
subtitle, | ||
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,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,18 @@ | ||
module.exports = { | ||
'chinaisa.org.cn': { | ||
_name: '中国钢铁工业协会', | ||
'.': [ | ||
{ | ||
title: '栏目', | ||
docs: 'https://docs.rsshub.app/routes/new-media#zhong-guo-gang-tie-gong-ye-xie-hui-lan-mu', | ||
source: ['/gxportal/xfgl/portal/list.html'], | ||
target: (params, url) => { | ||
url = new URL(url); | ||
const columnId = url.searchParams.get('columnId'); | ||
|
||
return `/chinaisa${columnId ? `/${columnId}` : ''}`; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
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