Skip to content

Commit 520a5df

Browse files
committed
fix: use Intl.Segmenter for avatar first character extraction
Handles unicode characters made up of multiple code points correctly.
1 parent 306077d commit 520a5df

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/components/BlueskyComment.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ function getHostname(uri: string): string {
3838
return uri
3939
}
4040
}
41+
42+
function firstChar(str: string): string {
43+
const segmenter = new Intl.Segmenter({ granularity: 'grapheme' })
44+
return Array.from(segmenter.segment(str))[0]?.segment ?? ''
45+
}
4146
</script>
4247

4348
<template>
@@ -70,7 +75,7 @@ function getHostname(uri: string): string {
7075
depth === 0 ? 'w-10 h-10' : 'w-8 h-8 text-sm',
7176
]"
7277
>
73-
{{ (comment.author.displayName || comment.author.handle).charAt(0).toUpperCase() }}
78+
{{ firstChar(comment.author.displayName || comment.author.handle).toUpperCase() }}
7479
</div>
7580
</a>
7681

@@ -98,7 +103,7 @@ function getHostname(uri: string): string {
98103
v-else
99104
class="w-6 h-6 rounded-full bg-border flex items-center justify-center text-fg-muted text-xs"
100105
>
101-
{{ (comment.author.displayName || comment.author.handle).charAt(0).toUpperCase() }}
106+
{{ firstChar(comment.author.displayName || comment.author.handle).toUpperCase() }}
102107
</div>
103108
</a>
104109
<a

0 commit comments

Comments
 (0)