fix: handle non-ASCII OG endpoint paths#501
Merged
matsuzaka-yuki merged 1 commit intoJul 11, 2026
Merged
Conversation
There was a problem hiding this comment.
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].pngpattern to a catch-all[...,slug]pattern. - Updates
getStaticPaths()to include.pnginside the generated catch-allslugparam so the endpoint can match/og/<slug>.png/while still emitting.pngoutput files.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更内容
修复中文等非 ASCII slug 下 OG 图片 endpoint 在 Astro 7 静态构建时可能触发
NoMatchingStaticPathFound的问题。具体改动:
src/pages/og/[...slug].png.ts改为src/pages/og/[...slug].tsgetStaticPaths()中把.png后缀合入 catch-allslug参数原因
原文件名
[...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
验证
结果:构建通过,Astro check 为 0 errors / 0 warnings / 0 hints。