tangled
alpha
login
or
join now
mackuba.eu
/
skythread
14
fork
atom
Thread viewer for Bluesky
14
fork
atom
overview
issues
pulls
pipelines
added "pluralize" helper
mackuba.eu
3 months ago
85a65937
b03097b3
+13
-4
2 changed files
expand all
collapse all
unified
split
src
components
posts
PostFooter.svelte
utils
text.ts
+3
-3
src/components/posts/PostFooter.svelte
···
4
4
import { linkToPostThread, linkToQuotesPage } from '../../router.js';
5
5
import { account } from '../../models/account.svelte.js';
6
6
import { showLoginDialog } from '../Dialogs.svelte';
7
7
-
import { showError } from '../../utils.js';
7
7
+
import { showError, pluralize } from '../../utils.js';
8
8
9
9
let { post, placement } = getPostContext();
10
10
let { quoteCount }: { quoteCount: number | undefined } = $props();
···
70
70
{#if post.replyCount > 0 && (placement == 'quotes' || placement == 'feed')}
71
71
<span>
72
72
<i class="fa-regular fa-message"></i>
73
73
-
<a href="{linkToPostThread(post)}">{post.replyCount > 1 ? `${post.replyCount} replies` : '1 reply'}</a>
73
73
+
<a href="{linkToPostThread(post)}">{pluralize(post.replyCount, 'reply', 'replies')}</a>
74
74
</span>
75
75
{/if}
76
76
···
78
78
{#if placement == 'quotes' || placement == 'feed' || post.isPageRoot}
79
79
<span>
80
80
<i class="fa-regular fa-comments"></i>
81
81
-
<a href={linkToQuotesPage(post.linkToPost)}>{quoteCount > 1 ? `${quoteCount} quotes` : '1 quote'}</a>
81
81
+
<a href={linkToQuotesPage(post.linkToPost)}>{pluralize(quoteCount, 'quote')}</a>
82
82
</span>
83
83
{:else}
84
84
<a href={linkToQuotesPage(post.linkToPost)}>
+10
-1
src/utils/text.ts
···
1
1
import DOMPurify from 'dompurify';
2
2
3
3
export function numberOfDays(days: number): string {
4
4
-
return (days == 1) ? '1 day' : `${days} days`;
4
4
+
return pluralize(days, 'day');
5
5
+
}
6
6
+
7
7
+
export function pluralize(value: number, word: string, plural?: string) {
8
8
+
if (value == 1) {
9
9
+
return `1 ${word}`;
10
10
+
} else {
11
11
+
plural = plural ?? `${word}s`;
12
12
+
return `${value} ${plural}`;
13
13
+
}
5
14
}
6
15
7
16
export function sanitizeHTML(html: string): string {