diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 86f4e575a2..fb66ededcc 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -312,6 +312,16 @@ highlightWrap = true # Images # These options configure how images are displayed. +# What to do when local image link is not resolved. +# Default: "" +# You can control what should happen if a local image can not be resolved to as +# a resource. If not set, the unresolved link is written as given into the resulting +# output. If set to `warning` the same happens and an additional warning is +# printed. If set to `error` an error message is printed and the build is +# aborted. +# Please note that this can not resolve files inside of your `static` directory. +image.errorlevel = "warning" + # Image effects. # See the documentation for how you can even add your own arbitrary effects to # the list. @@ -329,6 +339,17 @@ imageEffects.shadow = false # Links # These options configure how links are displayed. +# What to do when local page link is not resolved. +# Default: "" +# You can control what should happen if a local link can not be resolved to a +# page. If not set, the unresolved link is written as given into the resulting +# output. If set to `warning` the same happens and an additional warning is +# printed. If set to `error` an error message is printed and the build is +# aborted. +# Please note that with Hugo < 0.123.0 + `uglyURLs=true` this can lead to false +# negatives. +link.errorlevel = "warning" + # How to open external links. # Default: "_blank" # For external links you can define how they are opened in your browser. All diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md index 8bca33eadb..b72a2d800d 100644 --- a/exampleSite/content/basics/migration/_index.en.md +++ b/exampleSite/content/basics/migration/_index.en.md @@ -18,6 +18,16 @@ This document shows you what's new in the latest release and flags it with one o --- +## 5.24.1 (2024-02-17) {#5241} + +- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} If the theme can not resolve a link to a page or image, you can now generate warnings or errors during build by setting `link.errorlevel` or `image.errorlevel` to either `warning` or `error` in your `hugo.toml` respectively. By default this condition is silently ignored and the link is written as-is. + + Please note that a page link will generate false negatives if `uglyURLs=true` and it references an ordinary page before {{% badge color="fuchsia" icon="fab fa-hackerrank" title=" " %}}0.123.0{{% /badge %}}. + + Please note that an image link will generate false negatives if the file resides in your `static` directory. + +--- + ## 5.24.0 (2024-02-17) {#5240} - {{% badge color="fuchsia" icon="fab fa-hackerrank" title=" " %}}0.112.4{{% /badge %}} This release requires a newer Hugo version. diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html index 372981892d..642d6f3814 100644 --- a/layouts/partials/shortcodes/image.html +++ b/layouts/partials/shortcodes/image.html @@ -30,9 +30,11 @@ {{- $url = printf "%s?%s" $url $dest_url.RawQuery }} {{- end }} {{- end }} -{{- if not $image }} - {{- if and ($page.Site.Params.render_hooks.errorlevel "warning") (not (or (strings.HasPrefix .url "http://") (strings.HasPrefix .url "https://") )) }} - {{- warnf "%q: Image %s is not a resource but linked anyways." $page.File.Filename .url }} +{{- if and (not $image) (not $dest_url.IsAbs) }} + {{- if eq $page.Site.Params.image.errorlevel "warning" }} + {{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} + {{- else if eq $page.Site.Params.image.errorlevel "error" }} + {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} {{- end }} {{- end }} {{- if $dest_url.RawQuery }} diff --git a/layouts/partials/shortcodes/link.html b/layouts/partials/shortcodes/link.html index a4369078c3..b8f9038950 100644 --- a/layouts/partials/shortcodes/link.html +++ b/layouts/partials/shortcodes/link.html @@ -59,7 +59,11 @@ {{- $href = printf "%s#%s" $href . }} {{- end }} {{- else }} - {{- warnf "%q: no page was found for link '%s'" $page.File.Filename $u.Path }} + {{- if eq $page.Site.Params.link.errorlevel "warning" }} + {{- warnf "%q: link '%s' is not a page but linked anyways" $page.File.Filename $u.Path }} + {{- else if eq $page.Site.Params.link.errorlevel "error" }} + {{- errorf "%q: link '%s' is not a page" $page.File.Filename $u.Path }} + {{- end }} {{- end }} {{- end }} {{- $attributes = $attributes | merge (dict "href" $href) -}}