Skip to content

Commit 93d86fd

Browse files
committed
移除机器人评论
1 parent 6d18c6e commit 93d86fd

File tree

4 files changed

+81
-26
lines changed

4 files changed

+81
-26
lines changed

public/images/social-card-1.png

2.71 MB
Loading

public/images/social-card.png

47.4 KB
Loading

src/pages/guestbook/index.astro

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,53 @@ function getReactionEmoji(reaction: string) {
331331
.see-more-btn {
332332
display: inline-block;
333333
padding: 0.75rem 1.5rem;
334-
background-color: var(--bg-secondary-color);
335-
color: var(--text-color);
334+
background-color: var(--bg-secondary-color); /* Revert background */
335+
color: var(--text-color); /* Adjust text color */
336336
border: 1px solid var(--border-color);
337337
border-radius: 8px;
338338
text-decoration: none;
339-
transition: all 0.2s;
339+
transition: all 0.3s ease; /* Smoother transition */
340+
font-size: 1rem;
341+
font-weight: 600;
342+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* Subtle shadow */
343+
position: relative; /* For pseudo-elements */
344+
overflow: hidden; /* Hide overflowing pseudo-elements */
345+
z-index: 1;
346+
}
347+
348+
.see-more-btn::before,
349+
.see-more-btn::after {
350+
content: '';
351+
position: absolute;
352+
background: var(--accent-color); /* Accent color for border animation */
353+
transition: all 0.3s ease;
354+
z-index: -1;
355+
}
356+
357+
.see-more-btn::before {
358+
top: 0;
359+
left: 0;
360+
width: 0;
361+
height: 2px;
362+
}
363+
364+
.see-more-btn::after {
365+
bottom: 0;
366+
right: 0;
367+
width: 0;
368+
height: 2px;
369+
}
370+
371+
.see-more-btn:hover::before,
372+
.see-more-btn:hover::after {
373+
width: 100%;
340374
}
341375

342376
.see-more-btn:hover {
343-
background-color: var(--accent-color);
344-
color: #ffffff;
345-
border-color: var(--accent-color);
377+
background-color: var(--bg-secondary-color); /* Keep background same on hover */
378+
border-color: var(--accent-color); /* Change border color on hover */
379+
transform: translateY(-2px); /* Lift effect on hover */
380+
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15); /* Enhanced shadow on hover */
346381
}
347382

348383
.quoted-reply {

src/scripts/fetch-comments.js

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ function processReplies(replies, parentId, discussionId, discussionTitle, level
210210
const processedReplies = []
211211

212212
for (const reply of replies) {
213+
// Filter out bot comments
214+
if (reply.author && reply.author.login.endsWith('[bot]')) {
215+
continue
216+
}
217+
213218
const processedReply = {
214219
id: reply.id,
215220
url: reply.url,
@@ -228,6 +233,18 @@ function processReplies(replies, parentId, discussionId, discussionTitle, level
228233
}
229234

230235
processedReplies.push(processedReply)
236+
237+
// 递归处理子回复
238+
if (reply.replies && reply.replies.nodes && reply.replies.nodes.length > 0) {
239+
const childReplies = processReplies(
240+
reply.replies.nodes,
241+
reply.id,
242+
discussionId,
243+
discussionTitle,
244+
level + 1
245+
)
246+
processedReplies.push(...childReplies)
247+
}
231248
}
232249

233250
return processedReplies
@@ -236,9 +253,12 @@ function processReplies(replies, parentId, discussionId, discussionTitle, level
236253
async function main() {
237254
try {
238255
const discussions = await fetchAllDiscussions()
239-
const allComments = []
256+
const allComments = discussions.flatMap((discussion) => {
257+
// Filter out bot discussions if necessary (though Giscus usually comments, not creates discussions)
258+
if (discussion.author && discussion.author.login.endsWith('[bot]')) {
259+
return []
260+
}
240261

241-
for (const discussion of discussions) {
242262
// Map the main discussion post
243263
const mainComment = {
244264
id: discussion.id,
@@ -257,25 +277,25 @@ async function main() {
257277
type: 'discussion'
258278
}
259279

260-
allComments.push(mainComment)
261-
262280
// 处理顶级评论
263-
const topLevelComments = discussion.comments.nodes.map((comment) => ({
264-
id: comment.id,
265-
url: comment.url,
266-
createdAt: comment.createdAt,
267-
author: comment.author,
268-
bodyHTML: comment.bodyHTML,
269-
reactionGroups: comment.reactionGroups,
270-
isDiscussion: false,
271-
title: discussion.title,
272-
discussionId: discussion.id,
273-
parentId: discussion.id, // 顶级评论的父级是 discussion
274-
replyToId: comment.replyTo ? comment.replyTo.id : null,
275-
replyToAuthor: comment.replyTo ? comment.replyTo.author.login : null,
276-
level: 1,
277-
type: 'comment'
278-
}))
281+
const topLevelComments = discussion.comments.nodes
282+
.filter(comment => !comment.author || !comment.author.login.endsWith('[bot]')) // Filter out bot comments
283+
.map((comment) => ({
284+
id: comment.id,
285+
url: comment.url,
286+
createdAt: comment.createdAt,
287+
author: comment.author,
288+
bodyHTML: comment.bodyHTML,
289+
reactionGroups: comment.reactionGroups,
290+
isDiscussion: false,
291+
title: discussion.title,
292+
discussionId: discussion.id,
293+
parentId: discussion.id, // 顶级评论的父级是 discussion
294+
replyToId: comment.replyTo ? comment.replyTo.id : null,
295+
replyToAuthor: comment.replyTo ? comment.replyTo.author.login : null,
296+
level: 1,
297+
type: 'comment'
298+
}))
279299

280300
allComments.push(...topLevelComments)
281301

0 commit comments

Comments
 (0)