From 6a134d4fe902de6f7456c9316d7cd71a4f921bc0 Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Sat, 27 Sep 2025 00:05:41 +0200 Subject: [PATCH] Add option to configure portable links behaviour: off, error or warning --- exampleSite/hugo.toml | 5 +++-- exampleSite/hugo.yaml | 5 +++-- layouts/_partials/docs/links/portable-image.html | 8 +++++++- layouts/_partials/docs/links/portable-link.html | 8 +++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/exampleSite/hugo.toml b/exampleSite/hugo.toml index 169ed1b..7836fe0 100644 --- a/exampleSite/hugo.toml +++ b/exampleSite/hugo.toml @@ -136,8 +136,9 @@ enableGitInfo = true # /!\ This is an experimental feature, might be removed or changed at any time # (Optional, experimental, default false) Enables portable links and link checks in markdown pages. # Portable links meant to work with text editors and let you write markdown without {{< relref >}} shortcode - # Theme will print warning if page referenced in markdown does not exists. - BookPortableLinks = true + # Theme will print warning or error if page referenced in markdown does not exists. + # Possible values are false | 'warning' | 'error' + BookPortableLinks = 'warning' # /!\ This is an experimental feature, might be removed or changed at any time # (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use. diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 9044a90..ad673dd 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -120,8 +120,9 @@ params: # /!\ This is an experimental feature, might be removed or changed at any time # (Optional, experimental, default false) Enables portable links and link checks in markdown pages. # Portable links meant to work with text editors and let you write markdown without {{< relref >}} shortcode - # Theme will print warning if page referenced in markdown does not exists. - BookPortableLinks: true + # Theme will print warning or error if page referenced in markdown does not exists. + # Possible values are false | 'warning' | 'error' + BookPortableLinks: 'warning' # /!\ This is an experimental feature, might be removed or changed at any time # (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use. diff --git a/layouts/_partials/docs/links/portable-image.html b/layouts/_partials/docs/links/portable-image.html index a65f2b2..b6946a0 100644 --- a/layouts/_partials/docs/links/portable-image.html +++ b/layouts/_partials/docs/links/portable-image.html @@ -13,7 +13,13 @@ {{- else with (resources.Get $path) -}} {{- $destination = .RelPermalink -}} {{- else -}} - {{- warnf "Image reference '%s' not found in '%s'" .Destination .Page.Permalink -}} + {{- $mode := .Page.Site.Params.BookPortableLinks -}} + {{- $message := printf "Image reference '%s' not found in '%s'" .Destination .Page.RelPermalink -}} + {{- if eq $mode "warning" -}} + {{- warnf $message -}} + {{- else if eq $mode "error" -}} + {{- errorf $message -}} + {{- end -}} {{- end -}} {{- with $url.RawQuery -}} diff --git a/layouts/_partials/docs/links/portable-link.html b/layouts/_partials/docs/links/portable-link.html index 6a68e1d..009db6b 100644 --- a/layouts/_partials/docs/links/portable-link.html +++ b/layouts/_partials/docs/links/portable-link.html @@ -16,7 +16,13 @@ {{- else with (resources.Get $path) -}} {{- $destination = .RelPermalink -}} {{- else -}} - {{- warnf "Reference '%s' not found in '%s'" .Destination .Page.RelPermalink -}} + {{- $mode := .Page.Site.Params.BookPortableLinks -}} + {{- $message := printf "Image reference '%s' not found in '%s'" .Destination .Page.RelPermalink -}} + {{- if eq $mode "warning" -}} + {{- warnf $message -}} + {{- else if eq $mode "error" -}} + {{- errorf $message -}} + {{- end -}} {{- end -}} {{- with $url.RawQuery -}}