Skip to content

fix: point imported docs' edit/view links at their own repository - #59

Merged
XtremeOwnageDotCom merged 1 commit into
mainfrom
fix/imported-docs-source-links
Sep 3, 2026
Merged

fix: point imported docs' edit/view links at their own repository#59
XtremeOwnageDotCom merged 1 commit into
mainfrom
fix/imported-docs-source-links

Conversation

@XtremeOwnageDotCom

Copy link
Copy Markdown
Contributor

Fixes #58.

What & why

An imported page's RelativePath is where it landed in this site (wherever destinationPath put it), not where it lives upstream. The site-wide repoUrl/editUri pattern therefore aimed "edit this page" at this repository, at a path that only exists in the other one:

imported page → https://github.com/org/site/edit/main/docs/imported/guides/setup.md   ✗ wrong repo, wrong path
after         → https://github.com/org/handbook/edit/main/docs/guides/setup.md        ✓

How links are resolved

Imported pages now carry their own SourceLinks, which the renderer treats as authoritative. Per source:

  1. Explicit repoUrl + editUri on the source — always wins. This is the "options in the configuration to manually set the repo, and base path" the issue asked for, and the only option for S3 sources, which have no repository to derive from.
  2. Derived from the clone for pull sources: the remote gives the host (an scp-style git@host:org/repo.git is rewritten to its https:// form), and the branch actually checked out plus sourcePath give the rest. Reading the real branch means a source that never pinned a reference still gets correct links, rather than us guessing main.
  3. No buttons at all when neither applies — a repo pinned to a tag or commit (detached, so there is no branch to build a URL around), a remote that is a local path, or an S3 source with nothing configured. The issue's "if not available, then don't show the button": a missing button beats one that 404s.

The date half of the issue

The issue guessed this "may also affect last edited by, created at" — it did. git-revision-date reads this repo's history, finds nothing for a file outside it, and fell through to the filesystem timestamp. For imported content that timestamp is the moment the import cloned the file, so every imported page reported itself as updated today, on every build. Pages sourced from outside the repository now get no git-derived dates instead of a fabricated one.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / chore

Checklist

  • dotnet format Netdocs.slnx --verify-no-changes passes
  • dotnet build Netdocs.slnx -c Release succeeds
  • dotnet test Netdocs.slnx -c Release passes (553, +21 new)
  • Added/updated tests for the change
  • Updated docs under docs-site/docs/** if behavior changed

Verification

Unit tests cover clone-URL rewriting (https/ssh/scp forms, and refusing to guess a host for a local path), derivation, explicit-config precedence, and every suppression case. Four more render a page through the real template engine to check what actually reaches the HTML.

Then end to end, with a real git repo imported into a real site:

edit link
local page org/site/edit/main/docs/index.md
imported page org/handbook/edit/main/docs/guides/setup.md
imported page, origin underivable no button, and no link into this repo

Mutation-checked: disabling the renderer branch fails exactly the two tests that assert imported behaviour, and nothing else.

Notes for reviewers

SourceLinks is deliberately a nullable record where the members are also nullable, because there are three distinct states: null means "use the site-wide pattern" (ordinary pages), a value with links means "use these", and a value with nulls means "this page has no source to link to". Collapsing the last two would bring the wrong-link bug back for any origin we cannot resolve.

The theme still gates the buttons behind the content.action.edit / content.action.view features, unchanged.

🤖 Generated with Claude Code

An imported page's RelativePath is where it landed in this site, not where it
lives upstream, so the site-wide repoUrl/editUri built an "edit this page" link
into this repository at a path that only exists in the other one.

Imported pages now carry their own SourceLinks, which the renderer treats as
authoritative. They are resolved per source: an explicit repoUrl/editUri wins,
otherwise both are derived from the clone -- the remote gives the host (an
scp-style git@host:org/repo.git is rewritten to https), and the branch actually
checked out plus sourcePath give the rest, so a source that never pinned a
reference still gets correct links. When neither is possible -- a detached
checkout with no branch to build a URL around, a remote that is a local path, or
an S3 source with nothing configured -- the page renders no button rather than
one that 404s, which is what the issue asked for.

Also stops imported pages being stamped with today's date. git-revision-date
reads this repository's history, finds nothing for a file outside it, and fell
through to the filesystem -- reporting the moment the import cloned the file, so
every imported page looked updated on every build. Pages whose source sits
outside the repository are now left without git-derived dates.

Fixes #58

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@XtremeOwnageDotCom
XtremeOwnageDotCom merged commit 5a9967f into main Sep 3, 2026
1 check passed
@XtremeOwnageDotCom
XtremeOwnageDotCom deleted the fix/imported-docs-source-links branch September 3, 2026 01:55
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.

Edit/View links do not work for imported docs

1 participant