fix: show date on herocard closes #2
This commit is contained in:
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 Image from './Image.svelte';
|
||||
import Content from './Content.svelte';
|
||||
import Title from './Title.svelte';
|
||||
import Description from './Description.svelte';
|
||||
import ReadMoreButton from './ReadMoreButton.svelte';
|
||||
import Wrapper from "./Wrapper.svelte";
|
||||
import Image from "./Image.svelte";
|
||||
import Content from "./Content.svelte";
|
||||
import Title from "./Title.svelte";
|
||||
import Description from "./Description.svelte";
|
||||
import ReadMoreButton from "./ReadMoreButton.svelte";
|
||||
import Metadata from "./Metadata.svelte";
|
||||
|
||||
const Card = Wrapper as typeof Wrapper & {
|
||||
Image: typeof Image;
|
||||
Metadata: typeof Metadata;
|
||||
Content: typeof Content;
|
||||
Title: typeof Title;
|
||||
Description: typeof Description;
|
||||
ReadMoreButton: typeof ReadMoreButton;
|
||||
}
|
||||
};
|
||||
|
||||
Card.Image = Image;
|
||||
Card.Metadata = Metadata;
|
||||
Card.Content = Content;
|
||||
Card.Title = Title;
|
||||
Card.Description = Description;
|
||||
|
||||
Reference in New Issue
Block a user