Skip to content

fix(refactor): rewrite absolute links in sub-pages when moving a section#1182

Merged
perber merged 4 commits into
mainfrom
fix/refactor-absolute-links-in-moved-subtree
Jun 20, 2026
Merged

fix(refactor): rewrite absolute links in sub-pages when moving a section#1182
perber merged 4 commits into
mainfrom
fix/refactor-absolute-links-in-moved-subtree

Conversation

@perber

@perber perber commented Jun 19, 2026

Copy link
Copy Markdown
Owner

When a section with sub-pages was moved, absolute markdown links inside those sub-pages pointing to sibling pages within the same section were not updated. rewritePathChangedSubtree only ran RewriteRelativeLinksForPathChange which explicitly skips absolute links, and sub-pages are excluded from rewriteAffectedPages (which handles external pages only).

Add a second pass using engine.Rewrite for absolute intra-subtree links, short-circuited via strings.Contains to avoid a redundant goldmark parse when no matching absolute links can be present. Also cache current.CalculatePath() to a single call per page.

Adds three tests covering: absolute links in sub-pages to sibling sub-pages, relative links in sub-pages to external pages, and a regression guard ensuring intra-subtree relative links remain unchanged after the move.

When a section with sub-pages was moved, absolute markdown links inside
those sub-pages pointing to sibling pages within the same section were
not updated. rewritePathChangedSubtree only ran RewriteRelativeLinksForPathChange
which explicitly skips absolute links, and sub-pages are excluded from
rewriteAffectedPages (which handles external pages only).

Add a second pass using engine.Rewrite for absolute intra-subtree links,
short-circuited via strings.Contains to avoid a redundant goldmark parse
when no matching absolute links can be present. Also cache
current.CalculatePath() to a single call per page.

Adds three tests covering: absolute links in sub-pages to sibling sub-pages,
relative links in sub-pages to external pages, and a regression guard
ensuring intra-subtree relative links remain unchanged after the move.
Copilot AI review requested due to automatic review settings June 19, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 link rewriting for moved sections by ensuring absolute Markdown links inside sub-pages (pointing to other pages within the moved subtree) are updated when the section is moved. It extends the existing subtree rewrite logic to cover absolute intra-subtree links that were previously skipped.

Changes:

  • Add a second rewrite pass in rewritePathChangedSubtree to rewrite absolute Markdown links within the moved subtree, with a strings.Contains short-circuit to avoid unnecessary parsing.
  • Cache current.CalculatePath() to avoid repeated path computation per page.
  • Add three regression tests covering absolute intra-subtree links, external relative links from sub-pages, and ensuring intra-subtree relative links remain unchanged.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/wiki/pages/refactor.go Adds a second-pass rewrite for absolute intra-subtree Markdown links during subtree path changes, with a cheap pre-check and minor perf cleanup.
internal/wiki/pages/pages_test.go Adds tests for the new absolute-link rewriting behavior and guards against unintended relative-link rewrites.

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

Comment thread internal/wiki/pages/pages_test.go Outdated
Comment thread internal/wiki/pages/pages_test.go Outdated
Comment thread internal/wiki/pages/pages_test.go Outdated
perber and others added 3 commits June 19, 2026 22:26
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@perber perber merged commit ac4245c into main Jun 20, 2026
9 checks passed
@perber perber deleted the fix/refactor-absolute-links-in-moved-subtree branch June 20, 2026 02:38
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