Skip to content

Commit

Permalink
Sort recent blog posts by created_at (#6814)
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens authored Sep 7, 2023
1 parent 5e5e0fa commit c5e557b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/lib/get-social-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function parseFeedPost(post) {
id: post.ID,
title: removeEntities(post.title),
excerpt: removeEntities(post.excerpt),
created_at: post.date,
created_at: new Date(post.date),
link: post.URL,
image: post.featured_image
};
Expand Down Expand Up @@ -59,7 +59,9 @@ async function getBlogPosts() {
feeds.forEach(feed => {
posts = posts.concat(feed.slice(0,3))
});
return posts.map(parseFeedPost);
return posts
.map(parseFeedPost)
.sort((a,b) => b.created_at - a.created_at);
} catch (error) {
console.error(error);
}
Expand Down
2 changes: 1 addition & 1 deletion app/pages/home-common/social.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class HomePageSocial extends React.Component {
'home-social__blog-section--white': i === 0,
'home-social__blog-section--gray': i !== 0
});
const timestamp = moment(new Date(post.created_at)).fromNow();
const timestamp = moment(post.created_at).fromNow();
return (
<div key={i} className={classes}>
{i !== 0 && (<hr />)}
Expand Down

0 comments on commit c5e557b

Please sign in to comment.