forked from chengxuanying/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.
use puppeter to load nytimes's image, fix morning post url, using official rss Co-authored-by: Reki Dunois <[email protected]>
- Loading branch information
1 parent
37ab8af
commit 472b293
Showing
3 changed files
with
53 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,48 +3,46 @@ const cheerio = require('cheerio'); | |
const utils = require('./utils'); | ||
|
||
module.exports = async (ctx) => { | ||
const url = 'https://m.cn.nytimes.com/morning-brief/'; | ||
const url = 'https://www.nytimes.com/svc/collections/v1/publish/https://www.nytimes.com/zh-hans/series/daily-briefing-chinese/rss.xml'; | ||
const response = await got({ | ||
method: 'get', | ||
url, | ||
}); | ||
const data = response.data; | ||
const $ = cheerio.load(data); | ||
const post = $('.article-list .regular-item') | ||
.map((index, elem) => { | ||
const $item = $(elem); | ||
const $link = $item.find('a'); | ||
|
||
return { | ||
title: $link.attr('title'), | ||
link: $link.attr('href'), | ||
}; | ||
}) | ||
.get(); | ||
const post = $('item').map((index, elem) => { | ||
const title = $(elem).find('title').text(); | ||
const link = $(elem).find('link').next().text(); | ||
return { | ||
link: link, | ||
title: title | ||
}; | ||
}).get(); | ||
|
||
const items = await Promise.all( | ||
post.map(async (item) => { | ||
const link = item.link; | ||
const result = await ctx.cache.tryGet(`nyt: ${link}`, async () => { | ||
const response = await got.get(link); | ||
const browser = await require('@/utils/puppeteer')(); | ||
|
||
return utils.ProcessFeed(response.data); | ||
}); | ||
const items = await Promise.all( | ||
post.map( | ||
async (item) => { | ||
// use puppeter cause all the image is lazy-load | ||
const result = utils.ProcessFeed(await utils.PuppeterGetter(ctx, browser, item.link), true); | ||
|
||
item.pubDate = result.pubDate; | ||
item.pubDate = result.pubDate; | ||
|
||
// Match 感谢|謝.*[email protected]。 | ||
const ending = /感(谢|謝);.*?cn\.letters@nytimes\.com。/g; | ||
// Match 感谢|謝.*[email protected]。 | ||
const ending = /感(谢|謝);.*?cn\.letters@nytimes\.com。/g; | ||
|
||
const matching = '<div class="article-paragraph">'; | ||
const formatted = '<br>' + matching; | ||
const matching = '<div class="article-paragraph">'; | ||
const formatted = '<br>' + matching; | ||
|
||
item.description = result.description.replace(ending, '').split(matching).join(formatted); | ||
item.description = result.description.replace(ending, '').split(matching).join(formatted); | ||
|
||
return Promise.resolve(item); | ||
}) | ||
return Promise.resolve(item); | ||
}) | ||
); | ||
|
||
browser.close(); | ||
|
||
ctx.state.data = { | ||
title: '纽约时报中文网|每日简报', | ||
link: url, | ||
|
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