Repository navigation
fix(docs): resolve relative doc links to absolute routes on nav-alias pages - #488
Conversation
… pages do not 404 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
❌ Deploy Preview for hivecommons-docs failed. Why did it fail? →
|
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
Read the tree, not just the diff — this looks correct to me.
Route mapping holds. getProjectFromSlug (src/app/docs/[...slug]/page.tsx:267-278) strips the project segment, so a rewritten /docs/hive/architecture becomes docSlug=['architecture'] with contentPath=docs/content/hive and hits the direct-file lookup at page.tsx:185-197 before the routeMap fallback. sourceBaseDir (page.tsx:223-234) gives hive for governor.md reached via the operations/governor alias, so architecture.md → /docs/hive/architecture — the exact repro in #487.
Verified against the real content. I ran rewriteRelativeDocLinks over every .md/.mdx under docs/content/ with the same baseDir the page computes: 5 files change, 29 link targets are rewritten, and all 29 resolve to an existing file under docs/content/ (hive/governor.md, agent-definition-yaml.md, agent-terminal.md, variable-substitution.md, macos.md). Nothing with a scheme, a leading /, an asset extension, or inside backticks was touched.
Non-blocking notes:
[](target.md)-style links (image inside the label) are skipped by the\[([^\]]*)\]label pattern (src/lib/rewriteDocLinks.ts:61). None exist in the tree today, so no action needed; just noting the limit.- The red Netlify checks are the known deploy-preview quota exhaustion (docs#419), not this change;
Check internal doc links, vitest, and lint-and-build are all green.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Read against the tree at main; this looks correct to me.
Route shape matches. The rewriter emits /docs/<dir-relative-to-docs/content>/<name>. That is exactly what the resolver serves: getProjectFromSlug (page.tsx:263-273) peels the project segment and getPageContent (page.tsx:184-196) does a direct docs/content/<project>/<path>.md lookup; general-section files (community/…) fall through to docsContentPath the same way. With dynamicParams = false (page.tsx:107) the only routes that exist are the ones generateStaticParams enumerates, and collectParams(docsContentPath) (page.tsx:393-405) adds every .md/.mdx file at precisely that path — so no rewritten link can target a route that is not pre-rendered.
Scope check against the content. Grepped docs/content for the forms the regex deliberately does not handle: linked images ([](x.md)), raw <a href="relative">, and extensionless targets containing a dot (which ANY_EXT would treat as an asset). None exist today, so those gaps are theoretical rather than regressions.
Ordering. Inserted after rewriteImagePaths and before removeCommentPatterns/sanitizeHtmlForMdx (page.tsx:247-250), mirroring the image rewrite; replaceTemplateVariables has already run, so templated destinations are resolved first.
The red checks are all Netlify (deploy-preview, header/redirect/pages rules) — the Free-team quota exhaustion already ruled on in #419, not this diff. Unit tests, TS/ESLint, lint-and-build and the internal link check are green.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
…#492) getProjectFromPath's /docs/crux arm (added in #490) and rewriteDocLinks' reference-style definition fallbacks (added in #488) were the only lines and branches left unexecuted in those two files. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📌 Fixes
Closes #487
📝 Summary of Changes
rewriteRelativeDocLinks(src/lib/rewriteDocLinks.ts), which resolves relative.md/.mdx/extensionless links against the source file's directory into root-absolute/docs/...routes (fragments, queries and CommonMark titles preserved; fenced/inline code, assets, external and absolute links untouched).buildContentright afterrewriteImagePaths, sharing asourceBaseDirhelper.Reproduction (live):
/docs/hive/operations/governorrendershref="architecture", which the browser resolves to/docs/hive/operations/architecture→ 404 (real page:/docs/hive/architecture).Validation
CI (vitest, TypeScript & ESLint, lint-and-build)
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88