Skip to content

Commit

Permalink
style: auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 25, 2021
1 parent 9e5baaa commit b970348
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
41 changes: 21 additions & 20 deletions lib/routes/nytimes/morning_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,36 @@ module.exports = async (ctx) => {
});
const data = response.data;
const $ = cheerio.load(data);
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 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 browser = await require('@/utils/puppeteer')();

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);
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 = /感(&#x8C22|&#x8B1D);.*?cn\.letters@nytimes\.com。/g;
// Match 感谢|謝.*[email protected]
const ending = /感(&#x8C22|&#x8B1D);.*?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();
Expand Down
5 changes: 1 addition & 4 deletions lib/routes/nytimes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const PuppeterGetter = async (ctx, browser, link) => {
const result = await ctx.cache.tryGet(`nyt: ${link}`, async () => {
const page = await browser.newPage();
await page.goto(link);
const response = await page.evaluate(
() =>
document.querySelector('body').innerHTML
);
const response = await page.evaluate(() => document.querySelector('body').innerHTML);
return response;
});
return result;
Expand Down

0 comments on commit b970348

Please sign in to comment.