This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
export let date: string | Date;
|
||||
export let readDuration: string | undefined;
|
||||
export let readDuration: number | undefined;
|
||||
export let rating: string | number | undefined;
|
||||
|
||||
const toDate = (d: string | Date) =>
|
||||
typeof d === "string" ? new Date(d) : d;
|
||||
@@ -10,6 +11,13 @@
|
||||
return isNaN(v.getTime()) ? "" : v.toISOString();
|
||||
};
|
||||
|
||||
function formatRating(rating: string | number) {
|
||||
if (typeof rating === "number") {
|
||||
return "⭐".repeat(rating);
|
||||
}
|
||||
return rating;
|
||||
}
|
||||
|
||||
const formatDate = (d: string | Date) => {
|
||||
try {
|
||||
return new Intl.DateTimeFormat("de-DE", {
|
||||
@@ -29,7 +37,13 @@
|
||||
>{formatDate(date)}</time>
|
||||
{/if}
|
||||
|
||||
{#if readDuration}
|
||||
<div class="text-sm text-neutral">{readDuration} mins read</div>
|
||||
{#if typeof readDuration === "number"}
|
||||
{#if readDuration > 1}
|
||||
<div class="text-sm text-neutral">{readDuration} mins read</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if rating}
|
||||
<div class="text-sm text-neutral">{formatRating(rating)}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user