diff --git a/server/internal/config/config.go b/server/internal/config/config.go index 5487f59..a57a9fc 100644 --- a/server/internal/config/config.go +++ b/server/internal/config/config.go @@ -50,8 +50,22 @@ func Load() *Config { ExpireTime: getEnvAsInt("JWT_EXPIRE_HOURS", 24*7), // 默认 7 天 }, CORS: CORSConfig{ + // 开发环境允许所有 localhost 端口 AllowOrigins: []string{ - getEnv("CORS_ORIGIN", "http://localhost:4321"), + "http://localhost:4321", + "http://localhost:4322", + "http://localhost:4323", + "http://localhost:4324", + "http://localhost:4325", + "http://localhost:4326", + "http://localhost:3000", + "http://127.0.0.1:4321", + "http://127.0.0.1:4322", + "http://127.0.0.1:4323", + "http://127.0.0.1:4324", + "http://127.0.0.1:4325", + "http://127.0.0.1:4326", + "http://127.0.0.1:3000", }, }, } diff --git a/server/novablog-server b/server/novablog-server index 5f98314..a34fcc2 100755 Binary files a/server/novablog-server and b/server/novablog-server differ diff --git a/src/components/TableOfContents.astro b/src/components/TableOfContents.astro new file mode 100644 index 0000000..06d22ea --- /dev/null +++ b/src/components/TableOfContents.astro @@ -0,0 +1,345 @@ +--- +interface Heading { + depth: number; + slug: string; + text: string; +} + +interface Props { + headings: Heading[]; +} + +const { headings } = Astro.props; + +// 过滤出 h2 和 h3 标题 +const tocItems = headings.filter(h => h.depth >= 2 && h.depth <= 3); +--- + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/src/layouts/PostLayout.astro b/src/layouts/PostLayout.astro index af4bbd9..3d2103b 100644 --- a/src/layouts/PostLayout.astro +++ b/src/layouts/PostLayout.astro @@ -4,11 +4,18 @@ import CommentSection from '../components/CommentSection.vue'; import LikeButton from '../components/LikeButton.vue'; import type { CollectionEntry } from 'astro:content'; -interface Props { - post: CollectionEntry<'blog'>; +interface Heading { + depth: number; + slug: string; + text: string; } -const { post } = Astro.props; +interface Props { + post: CollectionEntry<'blog'>; + headings?: Heading[]; +} + +const { post, headings = [] } = Astro.props; const { title, description, pubDate, updatedDate, heroImage, heroAlt, tags, author, category } = post.data; // 格式化日期 @@ -22,9 +29,63 @@ const formatDate = (date: Date) => { // 计算阅读时间(估算) const readingTime = Math.ceil(post.body?.split(/\s+/).length / 400) || 1; + +// 是否显示目录 +const hasToc = headings.length > 0; + +// 过滤出 h2 和 h3 标题 +const tocItems = headings.filter(h => h.depth >= 2 && h.depth <= 3); --- + + {hasToc && ( + + )} + + + {hasToc && ( +
+ )} + + + {hasToc && ( + + )} +
@@ -90,12 +151,37 @@ const readingTime = Math.ceil(post.body?.split(/\s+/).length / 400) || 1; )}
- +
-
-
- +
+ +
+
+ +
+ + + {hasToc && ( + + )}
@@ -125,4 +211,267 @@ const readingTime = Math.ceil(post.body?.split(/\s+/).length / 400) || 1;
-
\ No newline at end of file + + + + + \ No newline at end of file diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index cb5d557..7b060fb 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -24,9 +24,9 @@ interface Props { } const { post } = Astro.props; -const { Content } = await post.render(); +const { Content, headings } = await post.render(); --- - +