|
9 | 9 |
|
10 | 10 | type Item = NonNullable<typeof data.issues>[number] | NonNullable<typeof data.prs>[number]; |
11 | 11 |
|
| 12 | + /** |
| 13 | + * Checks whether a date is more recent than a month. |
| 14 | + * |
| 15 | + * @param date the date to check |
| 16 | + * @returns if it is more recent than a month |
| 17 | + */ |
12 | 18 | function isNew(date: Date) { |
13 | 19 | return date.getTime() >= new Date().getTime() - 1000 * 60 * 60 * 24 * 30; |
14 | 20 | } |
15 | 21 |
|
| 22 | + /** |
| 23 | + * Formats a date into "N days ago" format. |
| 24 | + * |
| 25 | + * @param date the input date |
| 26 | + * @returns the formatted string output |
| 27 | + */ |
16 | 28 | function daysAgo(date: Date) { |
17 | 29 | const days = Math.floor((new Date().getTime() - date.getTime()) / 1000 / 60 / 60 / 24); |
18 | 30 | return new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(-days, "day"); |
19 | 31 | } |
| 32 | +
|
| 33 | + /** |
| 34 | + * Checks if 2 dates are the same day. |
| 35 | + * |
| 36 | + * @param a the first date to compare |
| 37 | + * @param b the second date to compare |
| 38 | + * @returns if both dates are the same day |
| 39 | + */ |
| 40 | + function areSameDay(a: Date, b: Date) { |
| 41 | + return ( |
| 42 | + a.getDate() === b.getDate() && |
| 43 | + a.getMonth() === b.getMonth() && |
| 44 | + a.getFullYear() === b.getFullYear() |
| 45 | + ); |
| 46 | + } |
20 | 47 | </script> |
21 | 48 |
|
22 | 49 | <!-- snippets don't support generics: https://github.com/sveltejs/svelte/issues/15883 --> |
|
35 | 62 | {/snippet} |
36 | 63 |
|
37 | 64 | {#snippet listItem(item: Item, link: string)} |
38 | | - {@const date = new Date(item.created_at)} |
| 65 | + {@const lastUpdate = new Date(item.updated_at)} |
| 66 | + {@const isUpdated = !areSameDay(lastUpdate, new Date(item.created_at))} |
39 | 67 | <a |
40 | 68 | href={link} |
41 | 69 | class="flex items-center gap-6 rounded-xl px-4 py-3 transition-colors hover:bg-neutral-100 dark:hover:bg-neutral-800" |
|
63 | 91 | <span class="text-muted-foreground">#{item.number}</span> |
64 | 92 | </span> |
65 | 93 | <span> |
66 | | - {#if isNew(date)} |
67 | | - {daysAgo(date)} • |
| 94 | + {#if isNew(lastUpdate)} |
| 95 | + {daysAgo(lastUpdate)} • |
68 | 96 | {/if} |
69 | | - {new Intl.DateTimeFormat("en", { |
70 | | - dateStyle: "medium" |
71 | | - }).format(date)} |
| 97 | + <span class={{ italic: isUpdated }}> |
| 98 | + {new Intl.DateTimeFormat("en", { |
| 99 | + dateStyle: "medium" |
| 100 | + }).format(lastUpdate)} |
| 101 | + </span> |
72 | 102 | </span> |
73 | 103 | </div> |
74 | 104 | <MarkdownRenderer |
|
82 | 112 | h1: "h4", |
83 | 113 | h2: "h4", |
84 | 114 | h3: "h2", |
| 115 | + h4: "strong", |
| 116 | + sup: Transparent, |
| 117 | + blockquote: Transparent, |
| 118 | + p: Transparent, |
85 | 119 | pre: Transparent, |
86 | 120 | a: Transparent, |
87 | 121 | ul: Transparent |
|
0 commit comments