Skip to content

fix: handle non-ASCII OG endpoint paths#501

Merged
matsuzaka-yuki merged 1 commit into
LyraVoid:masterfrom
Dawn6666666:codex/fix-non-ascii-og-endpoint
Jul 11, 2026
Merged

fix: handle non-ASCII OG endpoint paths#501
matsuzaka-yuki merged 1 commit into
LyraVoid:masterfrom
Dawn6666666:codex/fix-non-ascii-og-endpoint

Conversation

@Dawn6666666

Copy link
Copy Markdown
Contributor

变更内容

修复中文等非 ASCII slug 下 OG 图片 endpoint 在 Astro 7 静态构建时可能触发 NoMatchingStaticPathFound 的问题。

具体改动:

  • src/pages/og/[...slug].png.ts 改为 src/pages/og/[...slug].ts
  • getStaticPaths() 中把 .png 后缀合入 catch-all slug 参数

原因

原文件名 [...slug].png.ts 会让 Astro 生成严格匹配 .png 结尾的 endpoint route pattern。若静态构建阶段在 trailingSlash: "always" 下把非 ASCII 图片链接规范化为 .png/,该 route pattern 无法匹配尾斜杠路径,导致 params 提取失败并触发 NoMatchingStaticPathFound

.png 移入 catch-all 参数后,endpoint 可以匹配 /og/中文路径.png/,最终静态产物仍会正确写为 .png 文件。

Fixes #500

验证

pnpm install --frozen-lockfile
pnpm exec astro build
pnpm exec astro check

结果:构建通过,Astro check 为 0 errors / 0 warnings / 0 hints。

@Dawn6666666 Dawn6666666 marked this pull request as ready for review July 6, 2026 02:46
Copilot AI review requested due to automatic review settings July 6, 2026 02:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Astro static builds failing to prerender OG image endpoints when the post slug contains non-ASCII characters (e.g., Chinese) and trailingSlash: "always" causes the crawler to normalize /og/<slug>.png into /og/<slug>.png/, which previously did not match the strict ...\.png$ route pattern.

Changes:

  • Switches the OG endpoint route from a strict [...,slug].png pattern to a catch-all [...,slug] pattern.
  • Updates getStaticPaths() to include .png inside the generated catch-all slug param so the endpoint can match /og/<slug>.png/ while still emitting .png output files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@matsuzaka-yuki matsuzaka-yuki merged commit 38c451c into LyraVoid:master Jul 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

中文 Slug 下 OG 图片 Endpoint 在 Astro 7 静态构建时失败

3 participants