fix: show date on herocard closes #2
This commit is contained in:
@@ -15,7 +15,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: { title, cover, icon },
|
data: { title, cover, icon, date },
|
||||||
collection,
|
collection,
|
||||||
body,
|
body,
|
||||||
id,
|
id,
|
||||||
@@ -30,6 +30,7 @@ const link = translatePath(`/${collection}/${id.split("/")[0]}`);
|
|||||||
<Card
|
<Card
|
||||||
classes={`grid gradient border-1 border-neutral overflow-hidden ${cover ? "grid-rows-[200px_1fr] xs:grid-rows-none xs:grid-cols-[1fr_200px]" : ""}`}>
|
classes={`grid gradient border-1 border-neutral overflow-hidden ${cover ? "grid-rows-[200px_1fr] xs:grid-rows-none xs:grid-cols-[1fr_200px]" : ""}`}>
|
||||||
<Card.Content classes="px-8 py-7 order-last xs:order-first">
|
<Card.Content classes="px-8 py-7 order-last xs:order-first">
|
||||||
|
{date && (<Card.Metadata date={date} />)}
|
||||||
<Card.Title classes="text-4xl flex items-center gap-2">
|
<Card.Title classes="text-4xl flex items-center gap-2">
|
||||||
{
|
{
|
||||||
icon &&
|
icon &&
|
||||||
|
|||||||
25
src/components/card/Metadata.svelte
Normal file
25
src/components/card/Metadata.svelte
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let date: string | Date;
|
||||||
|
|
||||||
|
const toDate = (d: string | Date) =>
|
||||||
|
typeof d === "string" ? new Date(d) : d;
|
||||||
|
|
||||||
|
const iso = (d: string | Date) => {
|
||||||
|
const v = toDate(d);
|
||||||
|
return isNaN(v.getTime()) ? "" : v.toISOString();
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDate = (d: string | Date) =>
|
||||||
|
new Intl.DateTimeFormat("de-DE", {
|
||||||
|
day: "2-digit",
|
||||||
|
month: "long",
|
||||||
|
year: "numeric",
|
||||||
|
}).format(toDate(d));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex gap-5">
|
||||||
|
{#if date}
|
||||||
|
<time class="text-sm text-neutral" datetime={iso(date)}
|
||||||
|
>{formatDate(date)}</time>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
import Wrapper from './Wrapper.svelte';
|
import Wrapper from "./Wrapper.svelte";
|
||||||
import Image from './Image.svelte';
|
import Image from "./Image.svelte";
|
||||||
import Content from './Content.svelte';
|
import Content from "./Content.svelte";
|
||||||
import Title from './Title.svelte';
|
import Title from "./Title.svelte";
|
||||||
import Description from './Description.svelte';
|
import Description from "./Description.svelte";
|
||||||
import ReadMoreButton from './ReadMoreButton.svelte';
|
import ReadMoreButton from "./ReadMoreButton.svelte";
|
||||||
|
import Metadata from "./Metadata.svelte";
|
||||||
|
|
||||||
const Card = Wrapper as typeof Wrapper & {
|
const Card = Wrapper as typeof Wrapper & {
|
||||||
Image: typeof Image;
|
Image: typeof Image;
|
||||||
|
Metadata: typeof Metadata;
|
||||||
Content: typeof Content;
|
Content: typeof Content;
|
||||||
Title: typeof Title;
|
Title: typeof Title;
|
||||||
Description: typeof Description;
|
Description: typeof Description;
|
||||||
ReadMoreButton: typeof ReadMoreButton;
|
ReadMoreButton: typeof ReadMoreButton;
|
||||||
}
|
};
|
||||||
|
|
||||||
Card.Image = Image;
|
Card.Image = Image;
|
||||||
|
Card.Metadata = Metadata;
|
||||||
Card.Content = Content;
|
Card.Content = Content;
|
||||||
Card.Title = Title;
|
Card.Title = Title;
|
||||||
Card.Description = Description;
|
Card.Description = Description;
|
||||||
|
|||||||
Reference in New Issue
Block a user