Skip to content

fix: _print output respects relativeURLs=true (#2638) - #2709

Open
greekera1000 wants to merge 2 commits into
google:mainfrom
greekera1000:fix/print-relative-urls
Open

fix: _print output respects relativeURLs=true (#2638)#2709
greekera1000 wants to merge 2 commits into
google:mainfrom
greekera1000:fix/print-relative-urls

Conversation

@greekera1000

Copy link
Copy Markdown

Fixes #2638

Problem

The _print/ output used absolute (root-relative) URLs even when the site sets relativeURLs = 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 relativeURLs search-and-replace pass on output formats it classifies as HTML (isHTML: true). The print output format left isHTML unset 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: true on the print output format (removes the stale FIXME).

Why the #14381 workaround is no longer needed

The print format sets permalinkable: false, and Hugo only generates the aliases that #14381 concerned when both isHTML and permalinkable are true — so enabling isHTML never 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 with print output enabled and relativeURLs: true, then asserts the _print page 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 _print aliases generated.

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.

_print url does not respect relativeURLs=true

1 participant