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 #930 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
15 changed files
with
210 additions
and
133 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 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 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 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 |
---|---|---|
@@ -1,45 +1,54 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { app, os, sv, getSignedSearchParams } = require('./utils'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
|
||
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; | ||
} | ||
const { rootUrl, getSearchParams } = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const searchParams = getSignedSearchParams({ | ||
app, | ||
os, | ||
sv, | ||
}); | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50; | ||
|
||
const apiUrl = `${rootUrl}/v2/article/hot/list`; | ||
|
||
const link = 'https://www.cls.cn/v2/article/hot/list'; | ||
const response = await got({ | ||
method: 'get', | ||
url: link, | ||
searchParams, | ||
url: apiUrl, | ||
searchParams: getSearchParams(), | ||
}); | ||
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), | ||
})) | ||
|
||
let items = response.data.data.slice(0, limit).map((item) => ({ | ||
title: item.title || item.brief, | ||
link: `${rootUrl}/detail/${item.id}`, | ||
pubDate: parseDate(item.ctime * 1000), | ||
})); | ||
|
||
items = await Promise.all( | ||
items.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.author = articleDetail.author?.name ?? item.author ?? ''; | ||
item.description = art(path.join(__dirname, 'templates/depth.art'), { | ||
articleDetail, | ||
}); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '财联社 - 热门文章排行榜', | ||
link: 'https://www.cls.cn/', | ||
link: rootUrl, | ||
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
'/depth/:category?': ['nczitzk'], | ||
'/hot': ['5upernova-heng'], | ||
'/hot': ['5upernova-heng', 'nczitzk'], | ||
'/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
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 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{{ if item.content }} | ||
{{ item.content }} | ||
{{ item.content }} | ||
{{ /if }} | ||
|
||
{{ if item.images }} | ||
{{ if item.images.length !== 0 }} | ||
<br> | ||
{{ each item.images i }} | ||
<img src="{{ i }}"> | ||
{{ /each }} | ||
{{ each item.images i }} | ||
<img src="{{ i }}"> | ||
{{ /each }} | ||
{{ /if }} |
Oops, something went wrong.
aa2a201
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rsshub-master – ./
rsshub-master.vercel.app
rsshub-master-auto-bot-ty.vercel.app
rsshub-master-git-master-auto-bot-ty.vercel.app