aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-01 17:59:30 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-01 18:06:46 +0100
commit11e3ee75fcab0ab54b2bc1713a402c5cc3070c2d (patch)
tree7cb478ac6b29f2b527eb3ec379b305b74dd4f0ba /src/components/organisms
parentdfdbf6cac1fe3719dc71e130129d28e04ba4e225 (diff)
refactor(pages): refine Topic pages
* add useTopic and useTopicsList hooks to refresh data * add a table of contents * add Cypress tests
Diffstat (limited to 'src/components/organisms')
-rw-r--r--src/components/organisms/posts-list/posts-list.tsx14
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();