alpha
Login
or
Join now
flo-bit.dev
/
blog-template
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/flo-bit/blog-template. minimalistic astro blog template
flo-bit.dev/blog-template/
astro
blog
template
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
add ability to collapse comments
author
Florian
date
2 years ago
(Dec 2, 2024, 7:58 PM +0100)
commit
0ff4f1d8
0ff4f1d88836ea5533bc4e7874b4e7bacc9244c9
parent
2afb0374
2afb037414c089b630ad66d315ebdeae2b4ad2e7
+110
-73
2 changed files
Expand all
Collapse all
Unified
Split
src
components
bluesky
Comment.svelte
layouts
BaseLayout.astro
+109
-72
src/components/bluesky/Comment.svelte
View file
Reviewed
···
10
10
import RelativeTime from "./relative-time";
11
11
12
12
const { comment, depth = 0 } = $props();
13
13
+
14
14
+
let expanded = $state(true);
13
15
</script>
14
16
15
15
-
<div class="border-l dark:border-base-800 border-base-300 pl-3">
16
16
-
<div class="mt-2 pb-2">
17
17
-
<div
18
18
-
class="text-sm text-base-600 dark:text-base-500 flex items-center -ml-6"
19
19
-
>
17
17
+
{#snippet top(expand: boolean)}
18
18
+
<div class="text-sm text-base-600 dark:text-base-500 flex items-center -ml-6">
19
19
+
<div class="relative size-6">
20
20
<Avatar
21
21
src={comment.post.author.avatar}
22
22
link={`https://bsky.app/profile/${comment.post.author.did}`}
23
23
size="size-6"
24
24
/>
25
25
-
<a
26
26
-
target="_blank"
27
27
-
rel="noopener noreferrer nofollow"
28
28
-
class="ml-2 dark:text-base-400 hover:text-base-500 hover:dark:text-base-300"
29
29
-
href={`https://bsky.app/profile/${comment.post.author.did}`}
30
30
-
>
31
31
-
{comment.post.author.displayName || comment.post.author.handle}
32
32
-
</a>
25
25
+
{#if expand}
26
26
+
<button
27
27
+
class="absolute inset-0 size-6 bg-black/50 text-white rounded-full flex items-center justify-center"
28
28
+
onclick={() => (expanded = !expanded)}
29
29
+
>
30
30
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-3">
31
31
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
32
32
+
</svg>
33
33
34
34
-
<div class="text-xs ml-2 text-base-500">
35
35
-
<RelativeTime date={new Date(comment.post.record.createdAt)} locale="en" />
36
36
-
</div>
34
34
+
<span class="sr-only">expand comment</span>
35
35
+
</button>
36
36
+
{/if}
37
37
+
</div>
38
38
+
<a
39
39
+
target="_blank"
40
40
+
rel="noopener noreferrer nofollow"
41
41
+
class="ml-2 dark:text-base-400 hover:text-base-500 hover:dark:text-base-300"
42
42
+
href={`https://bsky.app/profile/${comment.post.author.did}`}
43
43
+
>
44
44
+
{comment.post.author.displayName || comment.post.author.handle}
45
45
+
</a>
46
46
+
47
47
+
<div class="text-xs ml-2 text-base-500">
48
48
+
<RelativeTime
49
49
+
date={new Date(comment.post.record.createdAt)}
50
50
+
locale="en"
51
51
+
/>
37
52
</div>
38
38
-
<div>{@html renderPostAsHtml(comment.post)}</div>
53
53
+
</div>
54
54
+
{/snippet}
55
55
+
56
56
+
<div class="pl-3 relative">
57
57
+
<button
58
58
+
class="group absolute -left-1.5 top-0 w-3 h-full flex items-center"
59
59
+
onclick={() => (expanded = !expanded)}
60
60
+
>
61
61
+
<div
62
62
+
class="mx-auto w-0.5 h-full bg-base-200 dark:bg-base-800 group-hover:bg-base-300 dark:group-hover:bg-base-700"
63
63
+
></div>
64
64
+
<span class="sr-only">collapse comment</span>
65
65
+
</button>
66
66
+
67
67
+
<div class="mt-2 pb-2">
68
68
+
{#if expanded}
69
69
+
{@render top(false)}
70
70
+
<div>{@html renderPostAsHtml(comment.post)}</div>
39
71
40
40
-
<div class="mt-2 flex gap-8 text-base-500 dark:text-base-400">
41
41
-
<a
42
42
-
href={atUriToPostUri(comment.post.uri)}
43
43
-
target="_blank"
44
44
-
rel="noopener noreferrer nofollow"
45
45
-
class="group inline-flex items-center gap-2 text-sm"
46
46
-
>
47
47
-
<svg
48
48
-
xmlns="http://www.w3.org/2000/svg"
49
49
-
fill="none"
50
50
-
viewBox="0 0 24 24"
51
51
-
stroke-width="1.5"
52
52
-
stroke="currentColor"
53
53
-
class="-m-1.5 size-7 rounded-full p-1.5 transition-all duration-100 group-hover:bg-accent-500/10 group-hover:text-accent-700 dark:group-hover:text-accent-400"
72
72
+
<div class="mt-2 flex gap-8 text-base-500 dark:text-base-400">
73
73
+
<a
74
74
+
href={atUriToPostUri(comment.post.uri)}
75
75
+
target="_blank"
76
76
+
rel="noopener noreferrer nofollow"
77
77
+
class="group inline-flex items-center gap-2 text-sm"
54
78
>
55
55
-
<path
56
56
-
stroke-linecap="round"
57
57
-
stroke-linejoin="round"
58
58
-
d="M12 20.25c4.97 0 9-3.694 9-8.25s-4.03-8.25-9-8.25S3 7.444 3 12c0 2.104.859 4.023 2.273 5.48.432.447.74 1.04.586 1.641a4.483 4.483 0 0 1-.923 1.785A5.969 5.969 0 0 0 6 21c1.282 0 2.47-.402 3.445-1.087.81.22 1.668.337 2.555.337Z"
59
59
-
/>
60
60
-
</svg>
61
61
-
<span class="sr-only">Replies</span>
62
62
-
{numberToHumanReadable(comment.post.replyCount)}
63
63
-
</a>
79
79
+
<svg
80
80
+
xmlns="http://www.w3.org/2000/svg"
81
81
+
fill="none"
82
82
+
viewBox="0 0 24 24"
83
83
+
stroke-width="1.5"
84
84
+
stroke="currentColor"
85
85
+
class="-m-1.5 size-7 rounded-full p-1.5 transition-all duration-100 group-hover:bg-accent-500/10 group-hover:text-accent-700 dark:group-hover:text-accent-400"
86
86
+
>
87
87
+
<path
88
88
+
stroke-linecap="round"
89
89
+
stroke-linejoin="round"
90
90
+
d="M12 20.25c4.97 0 9-3.694 9-8.25s-4.03-8.25-9-8.25S3 7.444 3 12c0 2.104.859 4.023 2.273 5.48.432.447.74 1.04.586 1.641a4.483 4.483 0 0 1-.923 1.785A5.969 5.969 0 0 0 6 21c1.282 0 2.47-.402 3.445-1.087.81.22 1.668.337 2.555.337Z"
91
91
+
/>
92
92
+
</svg>
93
93
+
<span class="sr-only">Replies</span>
94
94
+
{numberToHumanReadable(comment.post.replyCount)}
95
95
+
</a>
64
96
65
65
-
<a
66
66
-
href={atUriToPostUri(comment.post.uri)}
67
67
-
target="_blank"
68
68
-
rel="noopener noreferrer nofollow"
69
69
-
class="group inline-flex items-center gap-2 text-sm"
70
70
-
>
71
71
-
<svg
72
72
-
xmlns="http://www.w3.org/2000/svg"
73
73
-
fill="none"
74
74
-
viewBox="0 0 24 24"
75
75
-
stroke-width="1.5"
76
76
-
stroke="currentColor"
77
77
-
class="-m-1.5 size-7 rounded-full p-1.5 transition-all duration-100 group-hover:bg-accent-500/10 group-hover:text-accent-700 dark:group-hover:text-accent-400"
97
97
+
<a
98
98
+
href={atUriToPostUri(comment.post.uri)}
99
99
+
target="_blank"
100
100
+
rel="noopener noreferrer nofollow"
101
101
+
class="group inline-flex items-center gap-2 text-sm"
78
102
>
79
79
-
<path
80
80
-
stroke-linecap="round"
81
81
-
stroke-linejoin="round"
82
82
-
d="M21 8.25c0-2.485-2.099-4.5-4.688-4.5-1.935 0-3.597 1.126-4.312 2.733-.715-1.607-2.377-2.733-4.313-2.733C5.1 3.75 3 5.765 3 8.25c0 7.22 9 12 9 12s9-4.78 9-12Z"
83
83
-
/>
84
84
-
</svg>
85
85
-
<span class="sr-only">Likes</span>
86
86
-
{numberToHumanReadable(comment.post.likeCount)}
87
87
-
</a>
88
88
-
</div>
103
103
+
<svg
104
104
+
xmlns="http://www.w3.org/2000/svg"
105
105
+
fill="none"
106
106
+
viewBox="0 0 24 24"
107
107
+
stroke-width="1.5"
108
108
+
stroke="currentColor"
109
109
+
class="-m-1.5 size-7 rounded-full p-1.5 transition-all duration-100 group-hover:bg-accent-500/10 group-hover:text-accent-700 dark:group-hover:text-accent-400"
110
110
+
>
111
111
+
<path
112
112
+
stroke-linecap="round"
113
113
+
stroke-linejoin="round"
114
114
+
d="M21 8.25c0-2.485-2.099-4.5-4.688-4.5-1.935 0-3.597 1.126-4.312 2.733-.715-1.607-2.377-2.733-4.313-2.733C5.1 3.75 3 5.765 3 8.25c0 7.22 9 12 9 12s9-4.78 9-12Z"
115
115
+
/>
116
116
+
</svg>
117
117
+
<span class="sr-only">Likes</span>
118
118
+
{numberToHumanReadable(comment.post.likeCount)}
119
119
+
</a>
120
120
+
</div>
89
121
90
90
-
{#if comment.replies?.length > 0 && depth > 4}
91
91
-
<a
92
92
-
href={atUriToPostUri(comment.post.uri)}
93
93
-
target="_blank"
94
94
-
rel="noopener noreferrer nofollow"
95
95
-
class="text-sm text-base-500 dark:text-base-400 hover:dark:text-base-300 hover:text-base-600 font-medium"
96
96
-
>View more replies on bluesky</a
97
97
-
>
122
122
+
{#if comment.replies?.length > 0 && depth > 4}
123
123
+
<a
124
124
+
href={atUriToPostUri(comment.post.uri)}
125
125
+
target="_blank"
126
126
+
rel="noopener noreferrer nofollow"
127
127
+
class="text-sm text-base-500 dark:text-base-400 hover:dark:text-base-300 hover:text-base-600 font-medium"
128
128
+
>View more replies on bluesky</a
129
129
+
>
130
130
+
{/if}
131
131
+
{:else}
132
132
+
<button onclick={() => (expanded = true)}>
133
133
+
{@render top(true)}
134
134
+
</button>
98
135
{/if}
99
136
</div>
100
137
101
101
-
{#if comment.replies?.length > 0 && depth <= 4}
138
138
+
{#if comment.replies?.length > 0 && depth <= 4 && expanded}
102
139
{#each comment.replies.toSorted((a: any, b: any) => new Date(a.post.record.createdAt).getTime() - new Date(b.post.record.createdAt).getTime()) as reply}
103
140
<Comment comment={reply} depth={depth + 1} />
104
141
{/each}
+1
-1
src/layouts/BaseLayout.astro
View file
Reviewed
···
57
57
</div>
58
58
</div>
59
59
60
60
-
<div class="fixed inset-0 h-full w-full -z-10">
60
60
+
<div class="fixed inset-0 h-full w-full -z-50">
61
61
<div
62
62
class="h-full w-full max-w-6xl mx-auto bg-base-50 ring-1 ring-base-200 dark:bg-base-900 dark:ring-base-300/20 shadow-lg"
63
63
>