fix: _print output respects relativeURLs=true (#2638) - #2709
Open
greekera1000 wants to merge 2 commits into
Open
fix: _print output respects relativeURLs=true (#2638)#2709greekera1000 wants to merge 2 commits into
greekera1000 wants to merge 2 commits into
Conversation
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.
Fixes #2638
Problem
The
_print/output used absolute (root-relative) URLs even when the site setsrelativeURLs = true, while the rest of the site emitted relative URLs. This broke offline/local viewing of printable pages — CSS, JS, and images 404 when_print/*is opened from the file system — and consequently broke local HTML-to-PDF conversion.Root cause
Hugo only runs its
relativeURLssearch-and-replace pass on output formats it classifies as HTML (isHTML: true). Theprintoutput format leftisHTMLunset as a workaround for gohugoio/hugo#14381 (relative alias generation), so print pages never went through that rewrite and kept absolute URLs.Fix
Enable
isHTML: trueon theprintoutput format (removes the stale FIXME).Why the #14381 workaround is no longer needed
The
printformat setspermalinkable: false, and Hugo only generates the aliases that #14381 concerned when bothisHTMLandpermalinkableare true — so enablingisHTMLnever exercises that path here. The upstream fix for #14381 has also shipped and predates the theme's minimum Hugo (0.160.1).Testing
Adds an offline fixture-site regression test (
tests/fixture-site/print-relative-urls.test.mjs): builds a section withprintoutput enabled andrelativeURLs: true, then asserts the_printpage emits no absolute (leading-slash) asset URLs and references the site CSS relatively. Red without the fix, green with it.Also verified manually with a sub-path
baseURL(print CSS/JS and processed-image URLs flip from absolute to relative) and in a multilingual build (defaultContentLanguageInSubdir: true), with no spurious_printaliases generated.