From bd53c892962908fa28ff39835240515e52b62f61 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Fri, 5 Apr 2024 04:27:46 -0700 Subject: [PATCH] feat: add metadata display to blog posts --- package.json | 1 + pnpm-lock.yaml | 7 ++++ src/lib/components/Blog/PostCard.svelte | 12 +++++- src/lib/components/Blog/PostMetadata.svelte | 43 +++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0290826..fbc3bda 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "@sveltejs/adapter-vercel": "^5.2.0", "bits-ui": "^0.21.2", "clsx": "^2.1.0", + "dayjs": "^1.11.10", "marked": "^12.0.1", "marked-alert": "^2.0.1", "marked-katex-extension": "^5.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index db1063a..fbb1580 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ dependencies: clsx: specifier: ^2.1.0 version: 2.1.0 + dayjs: + specifier: ^1.11.10 + version: 1.11.10 marked: specifier: ^12.0.1 version: 12.0.1 @@ -1453,6 +1456,10 @@ packages: engines: {node: '>=4'} hasBin: true + /dayjs@1.11.10: + resolution: {integrity: sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==} + dev: false + /debug@4.3.4: resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} diff --git a/src/lib/components/Blog/PostCard.svelte b/src/lib/components/Blog/PostCard.svelte index be24dd7..ddb001f 100644 --- a/src/lib/components/Blog/PostCard.svelte +++ b/src/lib/components/Blog/PostCard.svelte @@ -2,6 +2,8 @@ import * as Card from '$lib/components/ui/card'; import Placeholder from '$lib/assets/img/galaxy.jpg'; import Button from '../ui/button/button.svelte'; + import PostMetadata from './PostMetadata.svelte'; + import { faker } from '@faker-js/faker'; export let title: string; export let blurb: string; @@ -10,8 +12,14 @@ -

{title}

+

{title}

{blurb}

+ faker.hacker.noun())} + secondaryTags={Array.from({ length: 2 }, () => faker.hacker.noun())} + time={Date.now() / 1000} + length={faker.number.int(1000)} + />
-

{description}

+

{description}

diff --git a/src/lib/components/Blog/PostMetadata.svelte b/src/lib/components/Blog/PostMetadata.svelte index e69de29..f130621 100644 --- a/src/lib/components/Blog/PostMetadata.svelte +++ b/src/lib/components/Blog/PostMetadata.svelte @@ -0,0 +1,43 @@ + + + + +
+

{date.format('MM/DD/YY')}

+ + {#each primaryTags as tag} + {tag} + {/each} + {#each secondaryTags as tag} + {tag} + {/each} + + + + {dayjs(date).fromNow()} | {Math.round(length / 238)} min read | {length} words + +