|
5 | 5 | interface Props { |
6 | 6 | href: string; |
7 | 7 | title: string; |
8 | | - duration?: number | string; // Duration in seconds (number) or time format like "1:20" or "1:05:30" (string) |
| 8 | + duration?: string; // Duration in time format like "1:20" or "1:05:30" |
9 | 9 | class?: string; |
10 | 10 | } |
11 | 11 |
|
12 | 12 | const { href, title, duration, class: className = '' }: Props = $props(); |
13 | | -
|
14 | | - function parseDuration(duration: number | string | undefined): string { |
15 | | - if (!duration) return ''; |
16 | | -
|
17 | | - if (typeof duration === 'string' && duration.includes(':')) { |
18 | | - return duration; |
19 | | - } |
20 | | -
|
21 | | - // If it's a number (seconds), format it |
22 | | - if (typeof duration === 'number') { |
23 | | - const mins = Math.floor(duration / 60); |
24 | | - const secs = Math.floor(duration % 60); |
25 | | - return `${mins}:${secs.toString().padStart(2, '0')}`; |
26 | | - } |
27 | | -
|
28 | | - // If it's a string number, parse and format it |
29 | | - const seconds = parseInt(duration, 10); |
30 | | - if (isNaN(seconds)) return ''; |
31 | | - const mins = Math.floor(seconds / 60); |
32 | | - const secs = Math.floor(seconds % 60); |
33 | | - return `${mins}:${secs.toString().padStart(2, '0')}`; |
34 | | - } |
35 | | -
|
36 | | - const durationFormatted = parseDuration(duration); |
37 | 13 | </script> |
38 | 14 |
|
39 | 15 | <a |
|
64 | 40 | <!-- Main title --> |
65 | 41 | <span class="video-card-title text-greyscale-900 dark:text-greyscale-100 flex-1"> |
66 | 42 | {title} |
67 | | - {#if durationFormatted} |
| 43 | + {#if duration} |
68 | 44 | <span class="video-card-duration-separator"> · </span> |
69 | | - <span class="video-card-duration">{durationFormatted}</span> |
| 45 | + <span class="video-card-duration">{duration}</span> |
70 | 46 | {/if} |
71 | 47 | </span> |
72 | 48 |
|
|
105 | 81 |
|
106 | 82 | <span class="video-card-title text-greyscale-900 dark:text-greyscale-100 flex-1"> |
107 | 83 | {title} |
108 | | - {#if durationFormatted} |
| 84 | + {#if duration} |
109 | 85 | <span class="video-card-duration-separator"> · </span> |
110 | | - <span class="video-card-duration">{durationFormatted}</span> |
| 86 | + <span class="video-card-duration">{duration}</span> |
111 | 87 | {/if} |
112 | 88 | </span> |
113 | 89 | </div> |
|
0 commit comments