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 cls hot articles 添加财联社热门文章排行榜 (DIYgod#12044)
* feat/add cls hot articles * rename router to one word * Apply suggestions from code review * import crypto * add heading 3 * refactor: migrate to v2 ---------
- Loading branch information
1 parent
ca9efda
commit dae0b25
Showing
12 changed files
with
232 additions
and
76 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 was deleted.
Oops, something went wrong.
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,82 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { app, os, sv, getSignedSearchParams } = require('./utils'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
|
||
const config = { | ||
1000: '头条', | ||
1003: '股市', | ||
1135: '港股', | ||
1007: '环球', | ||
1005: '公司', | ||
1118: '券商', | ||
1110: '基金', | ||
1006: '地产', | ||
1032: '金融', | ||
1119: '汽车', | ||
1111: '科创版', | ||
1160: '品见', | ||
1124: '期货', | ||
1176: '投教', | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const category = ctx.params.category || '1000'; | ||
const title = config[category]; | ||
if (!title) { | ||
throw Error('Bad category. See <a href="https://docs.rsshub.app/finance.html#cai-lian-she-shen-du">docs</a>'); | ||
} | ||
const searchParams = getSignedSearchParams({ | ||
app, | ||
os, | ||
sv, | ||
}); | ||
const baseUrl = 'https://www.cls.cn'; | ||
const link = `${baseUrl}/v3/depth/home/assembled/${category}`; | ||
const response = await got({ | ||
method: 'get', | ||
url: link, | ||
searchParams, | ||
}); | ||
|
||
let list = | ||
response.data.data.depth_list?.map((item) => ({ | ||
title: item.title || item.brief, | ||
link: `${baseUrl}/detail/${item.id}`, | ||
pubDate: new Date(item.ctime * 1000).toUTCString(), | ||
})) || []; | ||
|
||
list = list.concat( | ||
response.data.data.top_article.map((item) => ({ | ||
title: item.title || item.brief, | ||
link: `${baseUrl}/detail/${item.id}`, | ||
pubDate: new Date(item.ctime * 1000).toUTCString(), | ||
})) | ||
); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
const content = cheerio.load(detailResponse.data); | ||
const nextData = JSON.parse(content('script#__NEXT_DATA__').text()); | ||
const articleDetail = nextData.props.initialState.detail.articleDetail; | ||
|
||
item.description = art(path.join(__dirname, 'templates/depth.art'), { articleDetail }); | ||
item.author = articleDetail.author?.name; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `财联社 - ${title}`, | ||
link: `${baseUrl}/depth?id=${category}`, | ||
item: items, | ||
}; | ||
}; |
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,45 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { app, os, sv, getSignedSearchParams } = require('./utils'); | ||
|
||
async function getDescription(link, ctx) { | ||
const description = await ctx.cache.tryGet(link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: link, | ||
}); | ||
const content = cheerio.load(detailResponse.data); | ||
|
||
return content('div.detail-content').html(); | ||
}); | ||
return description; | ||
} | ||
|
||
module.exports = async (ctx) => { | ||
const searchParams = getSignedSearchParams({ | ||
app, | ||
os, | ||
sv, | ||
}); | ||
|
||
const link = 'https://www.cls.cn/v2/article/hot/list'; | ||
const response = await got({ | ||
method: 'get', | ||
url: link, | ||
searchParams, | ||
}); | ||
const items = await Promise.all( | ||
response.data.data.map(async (item) => ({ | ||
title: item.title || item.brief, | ||
link: `https://www.cls.cn/detail/${item.id}`, | ||
pubDate: new Date(item.ctime * 1000).toUTCString(), | ||
description: await getDescription(`https://www.cls.cn/detail/${item.id}`, ctx), | ||
})) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '财联社 - 热门文章排行榜', | ||
link: 'https://www.cls.cn/', | ||
item: items, | ||
}; | ||
}; |
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,5 @@ | ||
module.exports = { | ||
'/depth/:category?': ['nczitzk'], | ||
'/hot': ['5upernova-heng'], | ||
'/telegraph/:category?': ['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,25 @@ | ||
module.exports = { | ||
'cls.cn': { | ||
_name: '财联社', | ||
'.': [ | ||
{ | ||
title: '电报', | ||
docs: 'https://docs.rsshub.app/finance.html#cai-lian-she', | ||
sources: ['/telegraph', '/'], | ||
target: '/cls/telegraph', | ||
}, | ||
{ | ||
title: '深度', | ||
docs: 'https://docs.rsshub.app/finance.html#cai-lian-she', | ||
sources: ['/depth'], | ||
target: (_, url) => `/cls/depth/${new URL(url).searchParams.get('id')}`, | ||
}, | ||
{ | ||
title: '热门文章排行榜', | ||
docs: 'https://docs.rsshub.app/finance.html#cai-lian-she', | ||
sources: ['/'], | ||
target: '/cls/hot', | ||
}, | ||
], | ||
}, | ||
}; |
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,5 @@ | ||
module.exports = (router) => { | ||
router.get('/depth/:category?', require('./depth')); | ||
router.get('/hot', require('./hot')); | ||
router.get('/telegraph/:category?', require('./telegraph')); | ||
}; |
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,10 @@ | ||
{{ if articleDetail.images }} | ||
{{ each articleDetail.images i }} | ||
<img src="{{ i }}"> | ||
{{ /each }} | ||
<br> | ||
{{ /if }} | ||
|
||
{{ if articleDetail.content }} | ||
{{@ articleDetail.content }} | ||
{{ /if }} |
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,10 @@ | ||
{{ if item.content }} | ||
{{ item.content }} | ||
{{ /if }} | ||
|
||
{{ if item.images }} | ||
<br> | ||
{{ each item.images i }} | ||
<img src="{{ i }}"> | ||
{{ /each }} | ||
{{ /if }} |
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,15 @@ | ||
const CryptoJS = require('crypto-js'); | ||
|
||
const getSignedSearchParams = (searchParams) => { | ||
searchParams = new URLSearchParams(searchParams); | ||
searchParams.sort(); | ||
searchParams.append('sign', CryptoJS.MD5(CryptoJS.SHA1(searchParams.toString()).toString()).toString()); | ||
return searchParams; | ||
}; | ||
|
||
module.exports = { | ||
appName: 'CailianpressWeb', | ||
os: 'web', | ||
sv: '7.7.5', | ||
getSignedSearchParams, | ||
}; |