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 #1315 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
13 changed files
with
481 additions
and
44 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
'/myft/:key': ['HenryQW'], | ||
'/:language/:channel?': ['HenryQW', 'xyqfer'], | ||
}; |
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,51 @@ | ||
const got = require('@/utils/got'); | ||
const parser = require('@/utils/rss-parser'); | ||
const cheerio = require('cheerio'); | ||
|
||
module.exports = async (ctx) => { | ||
const ProcessFeed = (content) => { | ||
// clean up the article | ||
content.find('div.o-share, aside, div.o-ads').remove(); | ||
|
||
return content.html(); | ||
}; | ||
|
||
const link = `https://www.ft.com/myft/following/${ctx.params.key}.rss`; | ||
|
||
const feed = await parser.parseURL(link); | ||
|
||
const items = await Promise.all( | ||
feed.items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const response = await got({ | ||
method: 'get', | ||
url: item.link, | ||
headers: { | ||
Referer: 'https://www.facebook.com', | ||
}, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
item.description = ProcessFeed($('article.js-article__content-body')); | ||
item.category = [$('.n-content-tag--with-follow').text()].concat( | ||
$('.article__right-bottom a.concept-list__concept') | ||
.map((i, e) => $(e).text().trim()) | ||
.get() | ||
); | ||
item.author = $('a.n-content-tag--author') | ||
.map((i, e) => $(e).text()) | ||
.get(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `FT.com - myFT`, | ||
link, | ||
description: `FT.com - myFT`, | ||
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
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,3 +1,4 @@ | ||
module.exports = function (router) { | ||
router.get('/myft/:key', require('./myft')); | ||
router.get('/:language/:channel?', require('./channel')); | ||
}; |
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,110 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
|
||
const columns = { | ||
article: 2, | ||
report: 3, | ||
visualization: 4, | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const { column = 'article', category = '0' } = ctx.params; | ||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; | ||
|
||
const rootUrl = 'https://dt.yicai.com'; | ||
const apiUrl = new URL('api/getNewsList', rootUrl).href; | ||
const currentUrl = new URL(column, rootUrl).href; | ||
|
||
const { data: response } = await got(apiUrl, { | ||
searchParams: { | ||
page: 1, | ||
rid: columns[column], | ||
cid: category, | ||
pageSize: limit, | ||
}, | ||
}); | ||
|
||
let items = response.data.data.slice(0, limit).map((item) => { | ||
const enclosureUrl = item.originVideo; | ||
const enclosureExt = enclosureUrl.split(/\./).pop(); | ||
|
||
return { | ||
title: item.newstitle, | ||
link: new URL(item.url, rootUrl).href, | ||
description: art(path.join(__dirname, 'templates/description.art'), { | ||
image: { | ||
src: item.originPic, | ||
alt: item.newstitle, | ||
}, | ||
intro: item.newsnotes, | ||
}), | ||
author: item.creatername, | ||
category: [item.channelrootname, item.channelname, item.NewsTypeName].filter((c) => c), | ||
guid: `yicai-dt-${item.newsid}`, | ||
pubDate: parseDate(item.utc_createdate), | ||
updated: parseDate(item.utc_lastdate), | ||
enclosure_url: enclosureUrl, | ||
enclosure_type: enclosureUrl ? `${enclosureExt === 'mp4' ? 'video' : 'application'}/${enclosureExt}` : undefined, | ||
upvotes: item.newsscore ?? 0, | ||
}; | ||
}); | ||
|
||
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); | ||
|
||
content('div.logintips').remove(); | ||
|
||
content('img').each((_, e) => { | ||
e = content(e); | ||
|
||
content(e).replaceWith( | ||
art(path.join(__dirname, 'templates/description.art'), { | ||
image: { | ||
src: e.prop('data-original') ?? e.prop('src'), | ||
alt: e.prop('alt'), | ||
width: e.prop('width'), | ||
height: e.prop('height'), | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
item.description += art(path.join(__dirname, 'templates/description.art'), { | ||
description: content('div.txt').html(), | ||
}); | ||
item.author = content('div.authortime h3').text(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
const { data: currentResponse } = await got(currentUrl); | ||
|
||
const $ = cheerio.load(currentResponse); | ||
|
||
const title = $('title').text(); | ||
const image = $('div.logo a img').prop('src'); | ||
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href; | ||
|
||
ctx.state.data = { | ||
item: items, | ||
title: `${$(`a[data-cid="${category}"]`).text()}${title}`, | ||
link: currentUrl, | ||
description: $('meta[name="keywords"]').prop('content'), | ||
language: 'zh', | ||
image, | ||
icon, | ||
logo: icon, | ||
subtitle: $('meta[name="description"]').prop('content'), | ||
author: title.split(/_/).pop(), | ||
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
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
Oops, something went wrong.