Resolve relative image and file URLs from their source file and resolve config paths from the content root. - #8
Merged
Merged
Conversation
…ve config paths from the content root.
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.
Summary
Relative image and file URLs in content now resolve from the file that wrote them, just like page links.
inguides/semantic-tones.mdxbecomes/guides/images/palette.svg, and a missing file fails the build.Previously only page links were resolved. Relative
src,posterandsrcsetvalues were left for the browser, which resolved them against the page URL. Page URLs end in a slash, so the image above loaded from/guides/semantic-tones/images/palette.svg, which doesn't exist.The rule
href,src,posterandsrcsetresolve from the source file. This covers Markdown images,<img>,<picture>,<video>/<source>/<track>, downloads, SVG<use>and iframes, plus shared header and footer files, which resolve from their own folder./assets/site.css, generated previews), special schemes such asdata:andcid:, and formaction, which names an endpoint..tssources are never matched, because they're bundled into hashed scripts.Config URLs start at the content root
siteConfig.jsonlives at the content root, so its relative URLs now resolve from there:assets/logo.svgbecomes/assets/logo.svgon every page. This coverslogo.href,logo.imageSrc,logo.imageSrcDark,style.href,consent.privacyPolicyUrland consent scriptsrc. Paths are normalized, and any query or hash is kept.Without this, a relative logo or stylesheet path would resolve against each page and fail every nested page. It also fixes consent scripts, which load in the browser and were already broken on nested pages.
Implementation
content-hrefs.tsis renamed tocontent-urls.ts.ContentRouteIndexnow holds pages and assets, and oneresolveContentUrlserves every URL attribute.page-urls.tsresolveshref,srcandposter.srcsetgets a parser that follows the HTML spec: each URL runs to the next whitespace, so commas insidedata:URLs stay intact.Behavior changes
src,posterorsrcsetmust name a real file, or the build fails. Inserve, the page shows the error.Docs
The links guide gains an Images and files section and the updated error message. The site configuration guide explains that config paths start at the content folder.
Testing
.tssources, paths that leave the content folder, i18n fallback, and index comparison.srcsetparsing, partials, base path, and missing files.