Skip to content

Commit c2897be

Browse files
feat: italic date if modified, improve body formatting and add docs
1 parent 2a76ffd commit c2897be

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/routes/tracker/[org]/[repo]/+page.svelte

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,41 @@
99
1010
type Item = NonNullable<typeof data.issues>[number] | NonNullable<typeof data.prs>[number];
1111
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+
*/
1218
function isNew(date: Date) {
1319
return date.getTime() >= new Date().getTime() - 1000 * 60 * 60 * 24 * 30;
1420
}
1521
22+
/**
23+
* Formats a date into "N days ago" format.
24+
*
25+
* @param date the input date
26+
* @returns the formatted string output
27+
*/
1628
function daysAgo(date: Date) {
1729
const days = Math.floor((new Date().getTime() - date.getTime()) / 1000 / 60 / 60 / 24);
1830
return new Intl.RelativeTimeFormat("en", { numeric: "auto" }).format(-days, "day");
1931
}
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+
}
2047
</script>
2148

2249
<!-- snippets don't support generics: https://github.com/sveltejs/svelte/issues/15883 -->
@@ -35,7 +62,8 @@
3562
{/snippet}
3663

3764
{#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))}
3967
<a
4068
href={link}
4169
class="flex items-center gap-6 rounded-xl px-4 py-3 transition-colors hover:bg-neutral-100 dark:hover:bg-neutral-800"
@@ -63,12 +91,14 @@
6391
<span class="text-muted-foreground">#{item.number}</span>
6492
</span>
6593
<span>
66-
{#if isNew(date)}
67-
{daysAgo(date)} •
94+
{#if isNew(lastUpdate)}
95+
{daysAgo(lastUpdate)} •
6896
{/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>
72102
</span>
73103
</div>
74104
<MarkdownRenderer
@@ -82,6 +112,10 @@
82112
h1: "h4",
83113
h2: "h4",
84114
h3: "h2",
115+
h4: "strong",
116+
sup: Transparent,
117+
blockquote: Transparent,
118+
p: Transparent,
85119
pre: Transparent,
86120
a: Transparent,
87121
ul: Transparent

0 commit comments

Comments
 (0)