-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathBlueskyComment.vue
More file actions
203 lines (190 loc) · 6.24 KB
/
BlueskyComment.vue
File metadata and controls
203 lines (190 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<script setup lang="ts">
import type { AppBskyRichtextFacet } from '@atproto/api'
import { segmentize } from '@atcute/bluesky-richtext-segmenter'
import type { Comment } from '#shared/types/blog-post'
type RichtextFeature =
| AppBskyRichtextFacet.Link
| AppBskyRichtextFacet.Mention
| AppBskyRichtextFacet.Tag
function getCommentUrl(comment: Comment): string {
return atUriToWebUrl(comment.uri) ?? '#'
}
const props = defineProps<{
comment: Comment
depth: number
}>()
const MaxDepth = 4
function getFeatureUrl(feature: RichtextFeature): string | undefined {
if (feature.$type === 'app.bsky.richtext.facet#link') return feature.uri
if (feature.$type === 'app.bsky.richtext.facet#mention')
return `https://bsky.app/profile/${feature.did}`
if (feature.$type === 'app.bsky.richtext.facet#tag')
return `https://bsky.app/hashtag/${feature.tag}`
}
const processedSegments = segmentize(props.comment.text, props.comment.facets).map(segment => ({
text: segment.text,
url: segment.features?.[0] ? getFeatureUrl(segment.features[0] as RichtextFeature) : undefined,
}))
function getHostname(uri: string): string {
try {
return new URL(uri).hostname
} catch {
return uri
}
}
</script>
<template>
<div :class="depth === 0 ? 'flex gap-3' : 'flex gap-3 mt-3'">
<!-- Avatar -->
<a
:href="`https://bsky.app/profile/${comment.author.handle}`"
target="_blank"
rel="noopener noreferrer"
class="shrink-0"
>
<img
v-if="comment.author.avatar"
:src="comment.author.avatar"
:alt="comment.author.displayName || comment.author.handle"
:class="['rounded-full', depth === 0 ? 'w-10 h-10' : 'w-8 h-8']"
width="40"
height="40"
loading="lazy"
/>
<div
v-else
:class="[
'rounded-full bg-border flex items-center justify-center text-fg-muted',
depth === 0 ? 'w-10 h-10' : 'w-8 h-8 text-sm',
]"
>
{{ (comment.author.displayName || comment.author.handle).charAt(0).toUpperCase() }}
</div>
</a>
<div class="flex-1 min-w-0">
<!-- Author info + timestamp -->
<div class="flex flex-wrap items-baseline gap-x-2 gap-y-0">
<a
:href="`https://bsky.app/profile/${comment.author.handle}`"
target="_blank"
rel="noopener noreferrer"
class="font-medium text-fg hover:underline"
>
{{ comment.author.displayName || comment.author.handle }}
</a>
<span class="text-fg-subtle text-sm">@{{ comment.author.handle }}</span>
<span class="text-fg-subtle text-sm">·</span>
<a
:href="getCommentUrl(props.comment)"
target="_blank"
rel="noopener noreferrer"
class="text-fg-subtle text-sm hover:underline"
>
<NuxtTime relative :datetime="comment.createdAt" />
</a>
</div>
<!-- Comment text with rich segments -->
<p class="text-fg-muted whitespace-pre-wrap">
<template v-for="(segment, i) in processedSegments" :key="i">
<a
v-if="segment.url"
:href="segment.url"
target="_blank"
rel="noopener noreferrer"
class="link"
>{{ segment.text }}</a
>
<template v-else>{{ segment.text }}</template>
</template>
</p>
<!-- Embedded images -->
<div
v-if="comment.embed?.type === 'images' && comment.embed.images"
class="flex flex-wrap gap-2"
>
<a
v-for="(img, i) in comment.embed.images"
:key="i"
:href="img.fullsize"
target="_blank"
rel="noopener noreferrer"
class="block"
>
<img
:src="img.thumb"
:alt="img.alt || 'Embedded image'"
class="rounded-lg max-w-48 max-h-36 object-cover"
loading="lazy"
/>
</a>
</div>
<!-- Embedded external link card -->
<a
v-if="comment.embed?.type === 'external' && comment.embed.external"
:href="comment.embed.external.uri"
target="_blank"
rel="noopener noreferrer"
class="flex gap-3 p-3 border border-border rounded-lg bg-bg-subtle hover:bg-bg-subtle/80 transition-colors no-underline"
>
<img
v-if="comment.embed.external.thumb"
:src="comment.embed.external.thumb"
:alt="comment.embed.external.title"
width="20"
height="20"
class="w-20 h-20 rounded object-cover shrink-0"
loading="lazy"
/>
<div class="min-w-0">
<div class="font-medium text-fg truncate">
{{ comment.embed.external.title }}
</div>
<div class="text-sm text-fg-muted line-clamp-2">
{{ comment.embed.external.description }}
</div>
<div class="text-xs text-fg-subtle mt-1 truncate">
{{ getHostname(comment.embed.external.uri) }}
</div>
</div>
</a>
<!-- Like/repost counts -->
<div
v-if="comment.likeCount > 0 || comment.repostCount > 0"
class="mt-2 flex gap-4 text-sm text-fg-subtle"
>
<span v-if="comment.likeCount > 0">
{{ $t('blog.atproto.like_count', { count: comment.likeCount }, comment.likeCount) }}
</span>
<span v-if="comment.repostCount > 0">
{{ $t('blog.atproto.repost_count', { count: comment.repostCount }, comment.repostCount) }}
</span>
</div>
<!-- Nested replies -->
<template v-if="comment.replies.length > 0">
<div v-if="depth < MaxDepth" class="mt-2 ps-2 border-is-2 border-border flex flex-col">
<BlueskyComment
v-for="reply in comment.replies"
:key="reply.uri"
:comment="reply"
:depth="depth + 1"
/>
</div>
<a
v-else
:href="getCommentUrl(comment.replies[0]!)"
target="_blank"
rel="noopener noreferrer"
class="mt-2 block text-sm link"
>
{{
$t(
'blog.atproto.more_replies',
{ count: comment.replies.length },
comment.replies.length,
)
}}
</a>
</template>
</div>
</div>
</template>