From 9cd2b1fe5990c96bd63c44f3cd13f6ecf3853921 Mon Sep 17 00:00:00 2001 From: Phil Ewels Date: Fri, 15 Mar 2024 17:16:00 +0100 Subject: [PATCH] Clean date with content collection config, not component --- src/components/DateStr.astro | 10 ---------- src/content/config.ts | 8 ++++++-- src/pages/blog/[...post].astro | 3 +-- src/pages/blog/index.astro | 3 +-- src/pages/podcast/[...episode].astro | 3 +-- src/pages/podcasts.astro | 3 +-- 6 files changed, 10 insertions(+), 20 deletions(-) delete mode 100644 src/components/DateStr.astro diff --git a/src/components/DateStr.astro b/src/components/DateStr.astro deleted file mode 100644 index 298efe2f..00000000 --- a/src/components/DateStr.astro +++ /dev/null @@ -1,10 +0,0 @@ ---- -export interface Props { - d: Date; -} -const { d } = Astro.props; - -const dateString = d.getDate() + " " + d.toLocaleString("default", { month: "long" }) + " " + d.getFullYear(); ---- - -{dateString} diff --git a/src/content/config.ts b/src/content/config.ts index b5498f24..05786803 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -11,7 +11,9 @@ const blogCollection = defineCollection({ icon: z.string(), tags: z.string(), // tags: z.array(z.string()).optional(), - date: z.date(), + date: z + .date() + .transform((d) => d.getDate() + " " + d.toLocaleString("default", { month: "long" }) + " " + d.getFullYear()), }), }); @@ -28,7 +30,9 @@ const podcastCollection = defineCollection({ icon: z.string(), tags: z.string(), // tags: z.array(z.string()).optional(), - date: z.date(), + date: z + .date() + .transform((d) => d.getDate() + " " + d.toLocaleString("default", { month: "long" }) + " " + d.getFullYear()), }), }); diff --git a/src/pages/blog/[...post].astro b/src/pages/blog/[...post].astro index 16ddfc28..6cbb2a5e 100644 --- a/src/pages/blog/[...post].astro +++ b/src/pages/blog/[...post].astro @@ -1,7 +1,6 @@ --- import { getCollection } from "astro:content"; import Page from "@layouts/Page.astro"; -import DateStr from "@components/DateStr.astro"; export async function getStaticPaths() { const blogPosts = await getCollection("blog"); @@ -23,7 +22,7 @@ const tags = entry.data.tags.split(",");

{entry.data.title}


diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 53d41534..0af2bb12 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -1,7 +1,6 @@ --- import { getCollection } from "astro:content"; import Page from "@layouts/Page.astro"; -import DateStr from "@components/DateStr.astro"; const posts = (await getCollection("blog")).sort( (a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(), @@ -29,7 +28,7 @@ const posts = (await getCollection("blog")).sort( {post.data.author}
  • - + {post.data.date}

  • diff --git a/src/pages/podcast/[...episode].astro b/src/pages/podcast/[...episode].astro index 1f382c5f..140b3f96 100644 --- a/src/pages/podcast/[...episode].astro +++ b/src/pages/podcast/[...episode].astro @@ -1,7 +1,6 @@ --- import { getCollection } from "astro:content"; import Page from "@layouts/Page.astro"; -import DateStr from "@components/DateStr.astro"; export async function getStaticPaths() { const episodes = await getCollection("podcast"); @@ -23,7 +22,7 @@ const tags = entry.data.tags.split(",");

    {entry.data.title}

    • {entry.data.author}
    • -
    • +
    • {entry.data.date}

    diff --git a/src/pages/podcasts.astro b/src/pages/podcasts.astro index e015df3c..9cdf9653 100644 --- a/src/pages/podcasts.astro +++ b/src/pages/podcasts.astro @@ -1,7 +1,6 @@ --- import { getCollection } from "astro:content"; import Page from "@layouts/Page.astro"; -import DateStr from "@components/DateStr.astro"; const episodes = (await getCollection("podcast")).sort( (a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(), @@ -43,7 +42,7 @@ const episodes = (await getCollection("podcast")).sort( {post.data.subtype}
  • - + {post.data.date}