chore: dev.to top posts route clean up (#5940)

Co-authored-by: dwemerx <dwemerx>
This commit is contained in:
Dwemer 2020-10-19 13:55:20 +03:00 committed by GitHub
parent 2badc10f87
commit 3f549e1c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 20 deletions

View File

@ -19,19 +19,13 @@ module.exports = async (ctx) => {
const $ = cheerio.load(html);
$('div.crayons-story__body').each(function () {
const post = {};
const author = $('.crayons-story__secondary', this).text().trim().replace(/\s\s+/g, ', ');
const title = $('.crayons-story__title a', this).text().trim();
const link = `https://dev.to${$('.crayons-story__title a', this).attr('href')}`;
const description = $('.crayons-story__tags', this).text().trim().replace(/\s\s+/g, ' ');
const pubDate = new Date($('.time-ago-indicator-initial-placeholder', this).attr('data-seconds') * 1000).toUTCString();
post.author = author;
post.title = title;
post.link = link;
post.description = description;
post.pubDate = pubDate;
const post = {
author: $('.crayons-story__secondary', this).text().trim().replace(/\s\s+/g, ', '),
title: $('.crayons-story__title a', this).text().trim(),
link: `https://dev.to${$('.crayons-story__title a', this).attr('href')}`,
description: $('.crayons-story__tags', this).text().trim().replace(/\s\s+/g, ' '),
pubDate: new Date($('.time-ago-indicator-initial-placeholder', this).attr('data-seconds') * 1000).toUTCString(),
};
posts.push(post);
});
@ -41,12 +35,6 @@ module.exports = async (ctx) => {
link,
description: 'Top dev.to posts',
language: 'en-us',
item: posts.map((post) => ({
title: post.title,
description: post.description,
link: post.link,
author: post.author,
pubDate: post.pubDate,
})),
item: posts,
};
};