Skip to content

fix(actions): avoid replacing edit/blob inside paths in view-source URL - #1

Merged
taoky merged 1 commit into
ustclug:masterfrom
Minsecrus:fix/actions-view-url
Nov 25, 2026
Merged

taoky merged 1 commit into
ustclug:masterfrom
Minsecrus:fix/actions-view-url

Conversation

@Minsecrus

Copy link
Copy Markdown

背景

在启用 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.md
  • https://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

AI 工具使用声明:本次问题排查、修改与验证使用了 Google Antigravity(Gemini 模型)辅助,改动已人工核对。

@taoky

taoky commented Nov 25, 2026

Copy link
Copy Markdown
Member

好像对本来就有 /edit/ 和 /blob/ 的还是有问题的,不过我们预期没有这样的文件,所以作为一个临时修复应该是 OK 的。

@taoky
taoky merged commit 5c3a821 into ustclug:master Nov 25, 2026
5 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.

2 participants