Skip to content

Commit 74b830a

Browse files
committed
修复build error
1 parent 75e8b71 commit 74b830a

2 files changed

Lines changed: 45 additions & 18 deletions

File tree

src/layouts/GalleryLayout.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
import { Mermaid } from '@/custom/components/advanced'
32
import { Footer, Header, ThemeProvider } from '@/custom/components/basic'
43
54
import BaseHead from '@/components/BaseHead.astro'

src/pages/guestbook/index.astro

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
---
22
import comments from '@/data/comments.json'
3-
// import { theme } from '@/site.config.ts'
3+
import { theme } from '@/site.config.ts'
4+
5+
// Define types for comments and reaction groups
6+
interface ReactionGroup {
7+
content: string
8+
users: {
9+
totalCount: number
10+
}
11+
}
12+
13+
interface Comment {
14+
id: string
15+
url: string
16+
createdAt: string
17+
author: {
18+
login: string
19+
avatarUrl: string
20+
url: string
21+
}
22+
bodyHTML: string
23+
reactionGroups?: ReactionGroup[] // Optional as it might not always be present
24+
isDiscussion: boolean
25+
title?: string // Optional, added in fetch-comments.js
26+
}
427
528
const title = 'Guestbook'
629
const description = 'A collection of all comments.'
@@ -26,7 +49,7 @@ function timeAgo(dateString: string | number | Date) {
2649
return `${years} years ago`
2750
}
2851
29-
function getReactionEmoji(reaction: string | number) {
52+
function getReactionEmoji(reaction: string) {
3053
const a = {
3154
THUMBS_UP: '👍',
3255
THUMBS_DOWN: '👎',
@@ -37,7 +60,8 @@ function getReactionEmoji(reaction: string | number) {
3760
ROCKET: '🚀',
3861
EYES: '👀'
3962
}
40-
return a[reaction] || ''
63+
// Type assertion to tell TypeScript that 'reaction' is a valid key
64+
return a[reaction as keyof typeof a] || ''
4165
}
4266
---
4367

@@ -497,16 +521,16 @@ function getReactionEmoji(reaction: string | number) {
497521
</style>
498522
</head>
499523
<body>
500-
<!-- <header class='floating-header'>
524+
<header class='floating-header'>
501525
<a href='/' class='header-brand'>{theme.title}</a>
502526
<nav class='header-nav'>
503-
{theme.header.menu.map((item) => <a href={item.link}>{item.title}</a>)}
527+
{theme.header.menu?.map((item) => <a href={item.link}>{item.title}</a>)}
504528
</nav>
505529
<div class='header-actions'>
506530
<a href='/search' title='Search'>Search</a>
507531
<button id='toggleDarkMode'>Theme</button>
508532
</div>
509-
</header> -->
533+
</header>
510534

511535
<div class='vscode-container'>
512536
<!-- 侧边栏 -->
@@ -550,7 +574,7 @@ function getReactionEmoji(reaction: string | number) {
550574

551575
<div class='editor-content'>
552576
{
553-
comments.map((comment, index) => (
577+
comments.map((comment: Comment, index: number) => (
554578
<div class='comment-item'>
555579
<div class='line-number'>{index + 1}</div>
556580
<div class='comment-content'>
@@ -575,7 +599,7 @@ function getReactionEmoji(reaction: string | number) {
575599
<div class='reactions'>
576600
{comment.reactionGroups &&
577601
comment.reactionGroups.map(
578-
(group: { users: { totalCount: unknown }; content: any }) =>
602+
(group: ReactionGroup) =>
579603
group.users.totalCount > 0 && (
580604
<div class='reaction'>
581605
{getReactionEmoji(group.content)} {group.users.totalCount}
@@ -609,21 +633,25 @@ function getReactionEmoji(reaction: string | number) {
609633

610634
<script>
611635
function toggleFolder(element: Element) {
612-
const folder = element.parentElement
613-
folder.classList.toggle('collapsed')
614-
const icon = element.querySelector('.folder-icon')
615-
if (folder.classList.contains('collapsed')) {
616-
icon.style.transform = 'rotate(-90deg)'
617-
} else {
618-
icon.style.transform = 'rotate(0deg)'
636+
const folder = element.parentElement as HTMLElement | null
637+
if (folder) {
638+
folder.classList.toggle('collapsed')
639+
const icon = element.querySelector('.folder-icon') as HTMLElement | null
640+
if (icon) {
641+
if (folder.classList.contains('collapsed')) {
642+
icon.style.transform = 'rotate(-90deg)'
643+
} else {
644+
icon.style.transform = 'rotate(0deg)'
645+
}
646+
}
619647
}
620648
}
621649

622650
// Make sidebar functional
623651
document.addEventListener('DOMContentLoaded', () => {
624652
const folders = document.querySelectorAll('.folder-header')
625-
folders.forEach((folder) => {
626-
folder.addEventListener('click', () => toggleFolder(folder))
653+
folders.forEach((folderElement) => {
654+
folderElement.addEventListener('click', () => toggleFolder(folderElement))
627655
})
628656

629657
// Dark Mode Toggle

0 commit comments

Comments
 (0)