Attempt client handling of post datetime

This commit is contained in:
2023-11-28 03:03:28 -06:00
parent 14f311d8f7
commit 083e8d5287
2 changed files with 28 additions and 14 deletions

14
src/components/Time.tsx Normal file
View File

@@ -0,0 +1,14 @@
import { format } from "date-fns";
import type { FunctionComponent } from "react";
type TimeProps = {
time: Date;
}
const Time: FunctionComponent<TimeProps> = ({ time }) => {
return (
<time className="font-mono">{format(time, "MM-dd-yyyy HH:mm OOO")}</time>
);
};
export default Time;

View File

@@ -1,15 +1,15 @@
--- ---
import General from "@layouts/General.astro"; import General from "@layouts/General.astro";
import { type CollectionEntry } from 'astro:content'; import Time from "@components/Time.jsx";
import { format } from "date-fns"; import { type CollectionEntry } from "astro:content";
interface Props { interface Props {
post: CollectionEntry<'blog'>; post: CollectionEntry<"blog">;
} }
const { post } = Astro.props; const { post } = Astro.props;
const { title, pubDate, tags } = post.data; const { title, pubDate, tags } = post.data;
const tagCount = tags.length; const tagCount = tags.length;
--- ---
<General title={title}> <General title={title}>
<div class="max-w-3xl mx-4"> <div class="max-w-3xl mx-4">
<h1> <h1>
@@ -18,16 +18,16 @@ const tagCount = tags.length;
</a> </a>
</h1> </h1>
<p class="mt-0 text-sm ml-5"> <p class="mt-0 text-sm ml-5">
<a href={post.slug}> <Time time={pubDate} client:load />
<time class="font-mono" datetime="{{ page.date | date: '%Y-%m-%dT%H:%M:%SZ' }}"> <span class="space-x-2">
{format(pubDate, "MM-dd-yyyy HH:mm OOO")} {
</time> tags.map((tag, i) =>
</a> // Ignore required due to whitespace sensitive content
<span class="space-x-2"> // prettier-ignore
{tags.map((tag, i) => ( <><a href={`/tags/${tag}`}>{tag}</a>{i < tagCount - 1 ? "," : ""}</>,
<><a href={`/tags/${tag}`}>{ tag }</a>{ i < tagCount - 1 ? ',' : ''}</> )
))} }
</span> </span>
<article> <article>
<slot /> <slot />
</article> </article>