fix(html): correct relative link depth on default-module subpages#808
Open
crowlbot wants to merge 2 commits into
Open
fix(html): correct relative link depth on default-module subpages#808crowlbot wants to merge 2 commits into
crowlbot wants to merge 2 commits into
Conversation
|
|
Symbol pages are written to `{short_path.path}/~/{name}.html` for every
module, including the main entrypoint. But `href_path_resolve` hard-coded
the main entrypoint to a directory depth of 1 when computing the `../`
prefix for links back to the root.
That is only correct when the main module's path is `.` (the usual
single-package case). When several entrypoints share a common ancestor,
the main module gets a deeper path (e.g. `index.ts`), so its symbol pages
live two directories deep yet linked back to the root with a single
`../` — producing 404s for stylesheets, search results and cross-links on
those subpages.
Compute the depth from the actual number of path segments instead,
treating `.` as zero segments so the common case is unchanged.
2df8d67 to
ba0f8b0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When HTML docs are generated for a package with multiple entrypoints, the pages for symbols belonging to the default/main module contain broken relative links: stylesheets fail to load, search-result links 404, and cross-links lose the base path. See #717 and #685.
For example, a symbol page rendered for the main module links back to the root with
../when it actually needs../../, so links like~/Foo.htmlresolve to/~/Foo.html(missing a path segment) and 404.Cause
Symbol pages are always written to
{short_path.path}/~/{name}.html, for every module including the main entrypoint (src/html/mod.rs). Buthref_path_resolvehard-coded the main entrypoint to a directory depth of 1 when computing the../prefix:That is only correct when the main module's path is
.(the common single-package case, where the page lives at./~/Foo.html). When several entrypoints share a common ancestor, the main module gets a real path such asindex.ts, so its symbol pages live atindex.ts/~/Foo.html— two directories deep — but were still linked back to the root with a single../. This also explains why #685 saw the bug depend on entrypoint ordering: it changes which module becomes the default and what path it gets.Fix
Compute the depth from the actual number of segments in
file.path, treating.as zero segments (it adds no directory). This unifies the main and non-main cases:.→ symbol page./~/Foo.html→../(unchanged)index.ts→ symbol pageindex.ts/~/Foo.html→../../(fixed)foo→foo/~/Bar.html→../../(unchanged)Added unit tests in
src/html/util.rspinning all three cases; the fullhtml_testsnapshot suite is unaffected.Fixes #717