From cc8bade886fee861f9ab7ad1d54fd5415ab2ec7b Mon Sep 17 00:00:00 2001 From: Alex Lebens Date: Tue, 10 Mar 2026 21:29:11 -0500 Subject: [PATCH] feat: move post metadata to snippet component --- .../snippets/PostMetadataSnippet.astro | 60 +++++++++++++++++++ src/pages/blog/[...slug].astro | 50 +--------------- 2 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 src/components/snippets/PostMetadataSnippet.astro diff --git a/src/components/snippets/PostMetadataSnippet.astro b/src/components/snippets/PostMetadataSnippet.astro new file mode 100644 index 0000000..61173d9 --- /dev/null +++ b/src/components/snippets/PostMetadataSnippet.astro @@ -0,0 +1,60 @@ +--- +import getReadingTime from 'reading-time'; + +import type { Post } from '@lib/directusTypes'; + +import Logo from '@components/images/Logo.astro'; +import { formatShortDate } from '@support/time'; +import { getDirectusImageURL } from '@/support/url'; + +interface Props { + post: Post; +} + +const { post } = Astro.props; + +const readingTime = getReadingTime(post.content || ''); +--- + +
+
    + {post.category && ( +
  1. + +
    +
    + +
    + {post.category.title} +
    +
    + + / + +
  2. + )} +
  3. + + {formatShortDate(post.published_date)} + + + / + +
  4. +
  5. + + {readingTime.minutes.toPrecision(1)} minutes + +
  6. +
+
\ No newline at end of file diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 69b5d75..5c28972 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -1,7 +1,6 @@ --- import { Image } from 'astro:assets'; -import getReadingTime from 'reading-time'; import { marked } from 'marked'; import markedShiki from 'marked-shiki'; import { createHighlighter } from 'shiki'; @@ -9,17 +8,16 @@ import { readItems, readSingleton } from '@directus/sdk'; import 'photoswipe/style.css'; import SocialShareButton from '@components/buttons/SocialShareButton.astro'; -import Logo from '@components/images/Logo.astro'; +import PostMetadataSnippet from '@/components/snippets/PostMetadataSnippet.astro'; import BaseLayout from '@layouts/BaseLayout.astro'; import directus from '@lib/directus'; -import { formatDate } from '@support/time'; import { getDirectusImageURL } from '@/support/url'; const post = Astro.props; export async function getStaticPaths() { const posts = await directus.request(readItems('posts', { - fields: ['*', 'category.*'], + fields: ['*', { category: ['*'] }], })); return posts.map((post) => ({ params: { slug: post.slug }, @@ -28,9 +26,6 @@ export async function getStaticPaths() { } const global = await directus.request(readSingleton('site_global')); -const category = post.category; - -const readingTime = getReadingTime(post.content || ''); const highlighter = await createHighlighter({ themes: ['github-light', 'github-dark'], @@ -101,46 +96,7 @@ const content = marked.parse(post.content || '');

{post.title}

-
    - {category && ( -
  1. - -
    -
    - -
    - {category.title} -
    -
    - - / - -
  2. - )} -
  3. - - {formatDate(post.published_date)} - - - / - -
  4. -
  5. - - {readingTime.minutes.toPrecision(1)} minutes to read - -
  6. -
+