aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2021-07-21 04:42:31 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2021-07-21 04:42:58 -0500
commite424680fc013c291bd7eea4dc63b96401e5126a8 (patch)
treeb39227c50b2c365c49694fa4f86b2630d428ebc2 /utils
parent437268370661087dbe31323efb18dfe1a518da33 (diff)
downloadhomepage-e424680fc013c291bd7eea4dc63b96401e5126a8.tar.xz
homepage-e424680fc013c291bd7eea4dc63b96401e5126a8.zip
Added a timestamp and sorts posts by timestamp
Diffstat (limited to 'utils')
-rw-r--r--utils/Posts.tsx16
1 files changed, 14 insertions, 2 deletions
diff --git a/utils/Posts.tsx b/utils/Posts.tsx
index d82467e..2a69629 100644
--- a/utils/Posts.tsx
+++ b/utils/Posts.tsx
@@ -7,6 +7,7 @@ marked.setOptions(markedOptions);
interface PostMetadata {
name: string;
+ lastUpdated: string;
}
interface Post {
@@ -45,9 +46,20 @@ async function getPostFromDirectory(directory : string) {
async function getPosts() : Promise<Post[]> {
const directories = await fs.readdir(POST_PATH);
- const posts = directories.map(getPostFromDirectory);
+ const posts = await Promise.all(directories.map(getPostFromDirectory));
- return await Promise.all(posts);
+ return posts.sort((post_a, post_b) => {
+ const a = new Date(post_a.meta.lastUpdated);
+ const b = new Date(post_b.meta.lastUpdated);
+
+ if(a === b)
+ return 0;
+
+ if(a > b)
+ return -1;
+
+ return 1;
+ });
}
async function getMarkdown(post : Post) : Promise<string> {