Skip to content

Commit

Permalink
feat(lib): filter test posts on categorizePostsByYear
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed May 20, 2023
1 parent 080bcfc commit 4926118
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/categorizePostsByYear.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Post } from 'contentlayer/generated'

export function categorizePostsByYear(posts: Post[]) {
const listOfAllYears = posts.map(post => {
const filteredPosts = posts.filter(post => !post.test)

const listOfAllYears = filteredPosts.map(post => {
const date = new Date(post.date)

return date.getFullYear()
Expand All @@ -12,9 +14,11 @@ export function categorizePostsByYear(posts: Post[]) {
const postsByYear = listOfUniqueYears.map(year => {
return {
year,
posts: posts.filter(post => new Date(post.date).getFullYear() === year)
posts: filteredPosts.filter(
post => new Date(post.date).getFullYear() === year
)
}
})

return postsByYear
return postsByYear.sort((a, b) => b.year - a.year)
}

0 comments on commit 4926118

Please sign in to comment.