diff --git a/src/components/blog/Hero.astro b/src/components/blog/Hero.astro index 5a409e5..b33eb5e 100644 --- a/src/components/blog/Hero.astro +++ b/src/components/blog/Hero.astro @@ -1,7 +1,7 @@ --- import { Image } from "astro:assets"; -import { getFormattedDate } from "@/utils"; import type { CollectionEntry } from "astro:content"; +import FormattedDate from "../FormattedDate.astro"; interface Props { content: CollectionEntry<"post">; @@ -10,15 +10,6 @@ interface Props { const { content: { data }, } = Astro.props; - -const datetime = data.publishDate.toISOString(); -const postDate = getFormattedDate(data.publishDate, { month: "long" }); - -const hasBeenUpdated = typeof data.updatedDate !== "undefined"; -const updatedDatetime = data.updatedDate?.toISOString(); -const updatedPostDate = hasBeenUpdated - ? getFormattedDate(data.updatedDate as Date, { month: "long" }) - : null; --- { @@ -35,14 +26,12 @@ const updatedPostDate = hasBeenUpdated ) }

{data.title}

- + { - hasBeenUpdated && ( + data.updatedDate && ( Last Updated: - + ) } diff --git a/src/components/blog/PostPreview.astro b/src/components/blog/PostPreview.astro index 5b6e2ec..e165150 100644 --- a/src/components/blog/PostPreview.astro +++ b/src/components/blog/PostPreview.astro @@ -1,23 +1,21 @@ --- import type { CollectionEntry } from "astro:content"; -import type { IElement } from "@/data/shared"; -import { getFormattedDate } from "@/utils"; +import type { HTMLTag, Polymorphic } from "astro/types"; +import FormattedDate from "../FormattedDate.astro"; -interface Props extends IElement { +type Props = Polymorphic<{ as: Tag }> & { post: CollectionEntry<"post">; withDesc?: boolean; -} +}; -const { post, as: Element = "div", withDesc = false } = Astro.props; -const date = new Date(post.data.publishDate); -const datetime = date.toISOString(); -const postDate = getFormattedDate(date); +const { post, as: Tag = "div", withDesc = false } = Astro.props; +const postDate = post.data.updatedDate ?? post.data.publishDate; --- - - + + {post.data.title} - + {withDesc && {post.data.description}} diff --git a/src/data/shared.ts b/src/data/shared.ts index 5a56779..0560830 100644 --- a/src/data/shared.ts +++ b/src/data/shared.ts @@ -1,11 +1,7 @@ -interface IElement { - readonly as?: keyof HTMLElementTagNameMap; -} - interface PaginationLink { url: string; text?: string; srLabel?: string; } -export type { IElement, PaginationLink }; +export type { PaginationLink };