Skip to content

Rebase relative links so source step docs work when viewed directly on GitHub#12

Open
pmalarme wants to merge 2 commits into
mainfrom
pmalarme-issue-7-renderer-rebase-relative-links-so-source-899b17
Open

Rebase relative links so source step docs work when viewed directly on GitHub#12
pmalarme wants to merge 2 commits into
mainfrom
pmalarme-issue-7-renderer-rebase-relative-links-so-source-899b17

Conversation

@pmalarme

@pmalarme pmalarme commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Fixes #7.

Problem

Step docs under .workshop/docs/steps/*.md render into the participant's root README.md, so their relative links/images were authored repo-root-relative (e.g. .workshop/solutions/01-basic/, .workshop/docs/assets/01-*.png). Those resolve in the rendered README, but when a source doc is opened directly on GitHub, GitHub resolves relative links against that file's folder, so the same targets 404.

Change (Option A)

  1. Author source docs source-relative. All 9 step docs with links + the 3 partials now use links/images relative to the doc's own folder (../assets/…, ../../solutions/…, 00-intro.md#…, ../steps/00-intro.md#…), so they resolve when viewed directly on GitHub.
  2. Rebasing pass in render_readme.py. New rebase_relative_links(text, base_dir=…) (with is_rebasable_url / resolve_relative_target helpers) rewrites relative link/image targets from source-relative to repo-root-relative when composing README.md. Absolute URLs (https://, mailto:), protocol-relative, pure anchors, root-absolute paths, and {{OWNER}}/{{REPO}} placeholder URLs pass through untouched; fragments and link titles are preserved. Wired into the header, footer, and step-body loaders.
  3. Lint rule (check K) in lint_steps.py. Rejects root-relative links and flags any link/image whose target doesn't exist (also catches stale paths like the old docs/assets/…), scanning both step docs and partials.
  4. Tests. Added 15 renderer tests (rebasing, absolute/anchor/placeholder pass-through, image paths, titles, integration) and a new test_lint_steps.py (source-relative pass, root-relative rejection, broken-image rejection, real-docs green).
  5. Docs. Updated .github/instructions/workshop.instructions.md to document the new source-relative convention.

Acceptance

  • ✅ Source step docs now render valid links both when viewed directly on GitHub and when inlined into README.md.
  • ✅ Lint fails on root-relative links and on links/images pointing at non-existent targets.
  • python -m pytest .workshop/scripts/tests103 passed; python .workshop/scripts/lint_steps.py0 failures.

Regression safety

The rendered README.md output is byte-identical before and after this change (verified by rendering the committed HEAD docs/scripts and the new ones and diffing) — zero participant-facing behavior change. No churn to README.md or .workshop_instance/ state.

pmalarme and others added 2 commits July 8, 2026 16:03
Source step docs and partials authored their relative links/images
repo-root-relative, so they resolved in the rendered README but 404'd
when the source doc was viewed directly on GitHub. Author them
source-relative instead and rebase to repo-root-relative at render time.

- render_readme.py: add rebase_relative_links() + is_rebasable_url() /
  resolve_relative_target() helpers; rebase step bodies and partials
  when composing README.md. Absolute URLs, anchors, and placeholder
  URLs pass through unchanged; rendered README is byte-identical.
- Convert all step docs and partials to source-relative links/images.
- lint_steps.py: add check K rejecting root-relative links and any
  link/image whose target does not exist.
- Add renderer + lint tests (rebasing, absolute/anchor pass-through,
  image paths, root-relative and broken-link rejection).
- Update workshop.instructions.md to document the new convention.

Fixes #7

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Rubber-duck review flagged that normpath can collapse an over-deep
`../` chain into a target starting with `..`, which the existence
check could resolve outside the repo and silently pass. Flag any
rebased target equal to `..` or starting with `../` as a failure so
README never gets a link pointing above the repo root.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

Renderer: rebase relative links so source step docs work when viewed directly on GitHub

1 participant