diff options
Diffstat (limited to 'src/components/organisms/posts-list')
| -rw-r--r-- | src/components/organisms/posts-list/posts-list.tsx | 14 | 
1 files changed, 13 insertions, 1 deletions
| diff --git a/src/components/organisms/posts-list/posts-list.tsx b/src/components/organisms/posts-list/posts-list.tsx index 783bc4e..c4c6fa1 100644 --- a/src/components/organisms/posts-list/posts-list.tsx +++ b/src/components/organisms/posts-list/posts-list.tsx @@ -40,10 +40,22 @@ export type PostData = Pick<      Required<Pick<PostPreviewMetaData, 'publicationDate'>>;  }; +/** + * Method to sort PageLink objects by name. + * + * @param {PageLink} a - A PageLink object. + * @param {PageLink} b - Another PageLink object. + * @returns {1 | -1 | 0} + */ +export const sortPostsByDate = (a: PostData, b: PostData) => +  new Date(b.meta.publicationDate).getTime() - +  new Date(a.meta.publicationDate).getTime(); +  const getPostsByYear = (posts: PostData[]) => {    const yearCollection = new Map<string, PostData[]>(); +  const sortedPosts = [...posts].sort(sortPostsByDate); -  for (const post of posts) { +  for (const post of sortedPosts) {      const currentPostYear = new Date(post.meta.publicationDate)        .getFullYear()        .toString(); | 
