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>
|
||||
Reference in New Issue
Block a user