Skip to content

Commit eb8c0da

Browse files
committed
fix: use Intl.Segmenter for avatar first character extraction
Handles unicode characters made up of multiple code points correctly.
1 parent 19eb93c commit eb8c0da

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/components/BlueskyComment.vue

Lines changed: 6 additions & 1 deletion
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>
@@ -65,7 +70,7 @@ function getHostname(uri: string): string {
6570
depth === 0 ? 'w-10 h-10' : 'w-8 h-8 text-sm',
6671
]"
6772
>
68-
{{ (comment.author.displayName || comment.author.handle).charAt(0).toUpperCase() }}
73+
{{ firstChar(comment.author.displayName || comment.author.handle).toUpperCase() }}
6974
</div>
7075
</a>
7176

0 commit comments

Comments
 (0)