Unverified Commit c0edf06d authored by Tomas Dabašinskas's avatar Tomas Dabašinskas Committed by GitHub

sort posts by date in descending order (#12303)

* sort posts by date in descending order

Hi, I'm extending getAllPosts function to sort posts array by date in descending order. 
Any feedback is appreciated

* sort posts by date timestamp in descending order

* Lint fix
Co-authored-by: 's avatarLuis Alvarez <luis@vercel.com>
parent 634e621a
......@@ -35,5 +35,9 @@ export function getPostBySlug(slug, fields = []) {
export function getAllPosts(fields = []) {
const slugs = getPostSlugs()
return slugs.map(slug => getPostBySlug(slug, fields))
const posts = slugs
.map(slug => getPostBySlug(slug, fields))
// sort posts by date in descending order
.sort((post1, post2) => (post1.date > post2.date ? '-1' : '1'))
return posts
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment