Repository navigation
fix(actions): avoid replacing edit/blob inside paths in view-source URL - #1
Merged
Merged
Conversation
Member
|
好像对本来就有 /edit/ 和 /blob/ 的还是有问题的,不过我们预期没有这样的文件,所以作为一个临时修复应该是 OK 的。 |
taoky
approved these changes
Nov 25, 2026
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.
背景
在启用
content.action.view时,partials/actions.html当前使用page.edit_url | replace(part, 'raw')进行无边界的全局替换。当域名、仓库路径或文件名本身包含edit(例如 Linux101-docs#121 中的docs/credits.md)时,生成的「查看本页的源代码」链接会被误替换为.../raw/master/docs/crraws.md,导致 404。上游
squidfunk/mkdocs-material已进入维护模式并关闭了同类修复 PR(squidfunk/mkdocs-material#8561),因此将此修复提交至ustclug/mkdocs-material。改动说明
src/templates/partials/actions.html(及对应的生成产物material/templates/partials/actions.html)中的替换逻辑由part = "blob" / "edit"+replace(part, 'raw')改为带斜杠边界且仅替换首次出现的part = "/blob/" / "/edit/"+replace(part, '/raw/', 1)。测试用例验证(Jinja2)
.../edit/master/docs/credits.md→.../raw/master/docs/credits.md.../blob/main/docs/credits.md→.../raw/main/docs/credits.mdhttps://git.mycredit.eu/org/repo/edit/main/docs/edit/text-editors.md→https://git.mycredit.eu/org/repo/raw/main/docs/edit/text-editors.md