Skip to content

Add --hugo-relative-image-links flag for portable image paths#456

Draft
klocke-io wants to merge 1 commit into
gardener:masterfrom
klocke-io:feat/relative-image-links
Draft

Add --hugo-relative-image-links flag for portable image paths#456
klocke-io wants to merge 1 commit into
gardener:masterfrom
klocke-io:feat/relative-image-links

Conversation

@klocke-io
Copy link
Copy Markdown
Member

Summary

  • Adds a new --hugo-relative-image-links CLI flag (default false)
  • When enabled, embedded resource links (images) are resolved as relative paths from the source node to the destination, instead of being prefixed with hugo-base-url
  • Threads the existing isEmbeddable boolean through ResolveResourceLink so the resolver can distinguish images from regular links

Motivation

Static site generators like VitePress do not support Hugo-style root-relative URL rewriting via a base URL prefix. This flag produces portable markdown image paths (e.g. ./image.png) that work across different SSGs without post-processing.

Changes

  • cmd/hugo/option.go: Added RelativeImageLinks field to Hugo config struct
  • cmd/app/flags.go: Added --hugo-relative-image-links CLI flag
  • pkg/nodeplugins/markdown/linkresolver/link_resolving.go: Extended Interface and implementation with isEmbeddable parameter; added relative path computation when flag is enabled
  • pkg/nodeplugins/markdown/document/document_worker.go: Pass isEmbeddable to ResolveResourceLink calls (false for links, true for embedded)
  • pkg/nodeplugins/markdown/linkresolver/linkresolverfakes/fake_interface.go: Updated generated fake for new signature
  • pkg/nodeplugins/markdown/linkresolver/link_resolving_test.go: Updated test call sites for new signature

Test plan

  • go build ./... passes
  • All existing tests pass (10/11 — the 1 pre-existing anchor test failure on master is unrelated)
  • Manual validation with a VitePress documentation bundle

When enabled, embedded resource links (images) are resolved as relative
paths from the source node to the destination instead of being prefixed
with hugo-base-url. This produces portable markdown paths like
./image.png that work with VitePress and other static site generators
that do not support Hugo-style root-relative URL rewriting.

The isEmbeddable boolean, already tracked in the link resolution chain,
is now threaded through to ResolveResourceLink so the resolver can
distinguish images from regular links and apply the relative path
computation only to embeddable resources.
@gardener-prow gardener-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 23, 2026
@gardener-prow
Copy link
Copy Markdown

gardener-prow Bot commented Apr 23, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kostov6 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gardener-prow gardener-prow Bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Indicates the PR's author has signed the cla-assistant.io CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant