From e424680fc013c291bd7eea4dc63b96401e5126a8 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Wed, 21 Jul 2021 04:42:31 -0500 Subject: Added a timestamp and sorts posts by timestamp --- components/Breadcrumbs/breadcrumbs.module.scss | 2 +- components/Breadcrumbs/index.tsx | 4 ++-- pages/logs/[directory].tsx | 4 +++- pages/logs/index.module.scss | 12 ++++++++++++ pages/logs/index.tsx | 12 +++++++----- pages/logs/logs.md | 2 -- posts/cgit-nginx-ubuntu/meta.json | 3 ++- posts/packaging-nebula-for-debian/meta.json | 3 ++- templates/Default/default.module.scss | 13 +++++++++++++ templates/Default/index.tsx | 8 +++++++- utils/Posts.tsx | 16 ++++++++++++++-- 11 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 pages/logs/index.module.scss diff --git a/components/Breadcrumbs/breadcrumbs.module.scss b/components/Breadcrumbs/breadcrumbs.module.scss index 104eec2..6facea4 100644 --- a/components/Breadcrumbs/breadcrumbs.module.scss +++ b/components/Breadcrumbs/breadcrumbs.module.scss @@ -12,4 +12,4 @@ .divider { margin: 0 0.3rem; -} \ No newline at end of file +} diff --git a/components/Breadcrumbs/index.tsx b/components/Breadcrumbs/index.tsx index ed650e3..c5a17b8 100644 --- a/components/Breadcrumbs/index.tsx +++ b/components/Breadcrumbs/index.tsx @@ -9,7 +9,7 @@ export type BreadcrumbsProps = { }; const Breadcrumbs : FC = ({children, className, ...props}) => ( -
+ {Children.map(children, (child, index) => { return ( <> @@ -22,7 +22,7 @@ const Breadcrumbs : FC = ({children, className, ...props}) => ); })} -
+ ); const Crumb : FC = ({children, ...props}) => ( diff --git a/pages/logs/[directory].tsx b/pages/logs/[directory].tsx index 00fe78d..c3760f7 100644 --- a/pages/logs/[directory].tsx +++ b/pages/logs/[directory].tsx @@ -1,4 +1,3 @@ -import path from 'path'; import { GetStaticProps, GetStaticPropsContext } from 'next'; import React, { FC } from 'react'; import { getPosts, getMarkdown, Post, getPostFromDirectory } from '../../utils/Posts'; @@ -11,10 +10,13 @@ interface Props { } const Page : FC = ({ post, markdown }) => { + const { lastUpdated } = post.meta; + return ( <> = ({ posts }) => { - console.log(posts); + + return( -
    + +
      { posts.map(({ directory, meta }) => (
    • {meta.name}
    • diff --git a/pages/logs/logs.md b/pages/logs/logs.md index 5515287..c177646 100644 --- a/pages/logs/logs.md +++ b/pages/logs/logs.md @@ -2,5 +2,3 @@ Eclectic thoughts, miscellany, and discursive drivel -- [Packaging Nebula for Debian](/logs/packaging-nebula-for-debian) -- [Installing cGit behind NGINX on Ubuntu](/logs/cgit-nginx-ubuntu) diff --git a/posts/cgit-nginx-ubuntu/meta.json b/posts/cgit-nginx-ubuntu/meta.json index 81968b4..1a800fa 100644 --- a/posts/cgit-nginx-ubuntu/meta.json +++ b/posts/cgit-nginx-ubuntu/meta.json @@ -1,3 +1,4 @@ { - "name": "Installing cGit behind NGINX on Ubuntu" + "name": "Installing cGit behind NGINX on Ubuntu", + "lastUpdated": "2021-07-17" } \ No newline at end of file diff --git a/posts/packaging-nebula-for-debian/meta.json b/posts/packaging-nebula-for-debian/meta.json index 2e4895c..1f8f362 100644 --- a/posts/packaging-nebula-for-debian/meta.json +++ b/posts/packaging-nebula-for-debian/meta.json @@ -1,3 +1,4 @@ { - "name": "Packaging Nebula for Debian" + "name": "Packaging Nebula for Debian", + "lastUpdated": "2021-07-19" } \ No newline at end of file diff --git a/templates/Default/default.module.scss b/templates/Default/default.module.scss index ba6096f..7dd99c5 100644 --- a/templates/Default/default.module.scss +++ b/templates/Default/default.module.scss @@ -1,4 +1,17 @@ .viewportOverrides { margin-top: 4em; margin-bottom: 3em; +} + +.date { + margin-top: 0.5em; + padding: 0.1em 0.2em; + display: block; +} + +@media screen and (min-width: 1000px) { + .date { + float: right; + padding: 0.1em 0.2em; + } } \ No newline at end of file diff --git a/templates/Default/index.tsx b/templates/Default/index.tsx index 8902bf8..f693da2 100644 --- a/templates/Default/index.tsx +++ b/templates/Default/index.tsx @@ -7,6 +7,7 @@ import styles from './default.module.scss'; export type DefaultPage = { className?: string; path?: string; + lastUpdated?: string; }; export type RelPathProps = { @@ -37,11 +38,16 @@ const RelPath : FC = ({path, ...props}) => { ); } -const DefaultPage : FC = ({className, children, path, ...props}) => ( +const LastUpdatedDate : FC = ({children}) => ( + Last Updated: {children} +) + +const DefaultPage : FC = ({className, lastUpdated, children, path, ...props}) => ( {path !== undefined ? : undefined} + {lastUpdated ? {lastUpdated} : undefined} {children} ); 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 { 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 { -- cgit v1.2.3