theme: allow errorlevel override on page level #870

This commit is contained in:
Sören Weber 2024-08-02 10:32:31 +02:00
parent 1961424436
commit f2799f8c41
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
7 changed files with 71 additions and 9 deletions

View file

@ -302,6 +302,7 @@ highlightWrap = true
# for the unresolved path. If set to `warning` the same happens and an additional # for the unresolved path. 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 # warning is printed. If set to `error` an error message is printed and the build
# is aborted. # is aborted.
# This can be overridden in the page's frontmatter.
include.errorlevel = "error" include.errorlevel = "error"
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -316,6 +317,7 @@ include.errorlevel = "error"
# printed. If set to `error` an error message is printed and the build is # printed. If set to `error` an error message is printed and the build is
# aborted. # aborted.
# Please note that this can not resolve files inside of your `static` directory. # Please note that this can not resolve files inside of your `static` directory.
# This can be overridden in the page's frontmatter.
image.errorlevel = "error" image.errorlevel = "error"
# Image effects. # Image effects.
@ -358,6 +360,7 @@ useDefaultRelref = false
# aborted. # aborted.
# Please note that with Hugo < 0.123.0 + `uglyURLs=true` this can lead to false # Please note that with Hugo < 0.123.0 + `uglyURLs=true` this can lead to false
# negatives. # negatives.
# This can be overridden in the page's frontmatter.
link.errorlevel = "error" link.errorlevel = "error"
# How to open external links. # How to open external links.
@ -469,4 +472,5 @@ customOpenapiURL = "" # "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"
# printed. If set to `error` an error message is printed and the build is # printed. If set to `error` an error message is printed and the build is
# aborted. # aborted.
# Please note that this can not resolve files inside of your `static` directory. # Please note that this can not resolve files inside of your `static` directory.
# This can be overridden in the page's frontmatter.
openapi.errorlevel = "error" openapi.errorlevel = "error"

View file

@ -26,6 +26,8 @@ This document shows you what's new in the latest release and flags it with one o
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The [`openapi` shortcode](shortcodes/openapi) is now able to resolve links to resources as well as to files in the file system (the old behavior). You can configure to generate warnings or errors during build by setting `openapi.errorlevel` to either `warning` or `error` in your `hugo.toml` if a path can not be resolved. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The [`openapi` shortcode](shortcodes/openapi) is now able to resolve links to resources as well as to files in the file system (the old behavior). You can configure to generate warnings or errors during build by setting `openapi.errorlevel` to either `warning` or `error` in your `hugo.toml` if a path can not be resolved.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Shortcodes supporting an `errorlevel` configuration can now have overridden values in the [frontmatter](cont/frontmatter/) section of each individual page.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme now comes with its own overridden version of the `relref` shortcode. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme now comes with its own overridden version of the `relref` shortcode.
While the usage of `relref` is obsolete and discouraged by Hugo for a while, existing installations may use it. In configurations using a `baseURL` with a subdirectory, the default `relref` implementation of Hugo was failing, so an overridden shortcode was necessary. While the usage of `relref` is obsolete and discouraged by Hugo for a while, existing installations may use it. In configurations using a `baseURL` with a subdirectory, the default `relref` implementation of Hugo was failing, so an overridden shortcode was necessary.

View file

@ -155,10 +155,35 @@ LastModifierEmail = ""
# parameter to individual code blocks. # parameter to individual code blocks.
highlightWrap = true highlightWrap = true
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Include
# These options configure how the include shortcode works.
# What to do when path is not resolved.
# Default: ""
# You can control what should happen if a path can not be resolved to as
# a resource or via the file system. If not set, no output will be written
# for the unresolved path. 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.
# If not set, the set value of your site's hugo.toml is used.
include.errorlevel = ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Images # Images
# These options configure how images are displayed. # 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.
# If not set, the set value of your site's hugo.toml is used.
image.errorlevel = ""
# Image effects. # Image effects.
# See the documentation for how you can even add your own arbitrary effects to # See the documentation for how you can even add your own arbitrary effects to
# the list. # the list.
@ -175,6 +200,22 @@ imageEffects.lightbox = true
# Default: false # Default: false
imageEffects.shadow = false 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.
# If not set, the set value of your site's hugo.toml is used.
link.errorlevel = ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# MathJax # MathJax
# These options configure how math formulae are displayed. # These options configure how math formulae are displayed.
@ -260,3 +301,14 @@ disableOpenapi = true
# version will be used. # version will be used.
# If not set, the set value of your site's hugo.toml is used. # If not set, the set value of your site's hugo.toml is used.
customOpenapiURL = "" # "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js" customOpenapiURL = "" # "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js"
# What to do when a local OpenAPI spec link is not resolved.
# Default: ""
# You can control what should happen if a local OpenAPI spec link can not be resolved
# to 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.
# If not set, the set value of your site's hugo.toml is used.
openapi.errorlevel = ""

View file

@ -32,9 +32,10 @@
{{- $src = printf "%s#%s" $src . }} {{- $src = printf "%s#%s" $src . }}
{{- end }} {{- end }}
{{- else }} {{- else }}
{{- if eq $page.Site.Params.image.errorlevel "warning" }} {{- $errorlevel := or $page.Params.image.errorlevel $page.Site.Params.image.errorlevel }}
{{- if eq $errorlevel "warning" }}
{{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} {{- warnf "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }}
{{- else if eq $page.Site.Params.image.errorlevel "error" }} {{- else if eq $errorlevel "error" }}
{{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }}
{{- end }} {{- end }}
{{- end }} {{- end }}

View file

@ -17,9 +17,10 @@
{{- if (fileExists .file) }} {{- if (fileExists .file) }}
{{- $content = .file | readFile }} {{- $content = .file | readFile }}
{{- else }} {{- else }}
{{- if eq $page.Site.Params.include.errorlevel "warning" }} {{- $errorlevel := or $page.Params.include.errorlevel $page.Site.Params.include.errorlevel }}
{{- if eq $errorlevel "warning" }}
{{- warnf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }} {{- warnf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }}
{{- else if eq $page.Site.Params.include.errorlevel "error" }} {{- else if eq $errorlevel "error" }}
{{- errorf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }} {{- errorf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }}
{{- end }} {{- end }}
{{- end }} {{- end }}

View file

@ -60,6 +60,7 @@
{{- else }} {{- else }}
{{- $linkPage = $page.Page }} {{- $linkPage = $page.Page }}
{{- end }} {{- end }}
{{- $errorlevel := or $page.Params.link.errorlevel $page.Site.Params.link.errorlevel }}
{{- with $linkPage }} {{- with $linkPage }}
{{- $href = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }} {{- $href = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
{{- with $u.RawQuery }} {{- with $u.RawQuery }}
@ -68,7 +69,7 @@
{{- with $u.Fragment }} {{- with $u.Fragment }}
{{- $ctx := dict {{- $ctx := dict
"contentPath" $page.File.Filename "contentPath" $page.File.Filename
"errorLevel" $page.Site.Params.link.errorlevel "errorLevel" $errorlevel
"page" $linkPage "page" $linkPage
"parsedURL" $u "parsedURL" $u
"renderHookName" "link" "renderHookName" "link"
@ -77,9 +78,9 @@
{{- $href = printf "%s#%s" $href . }} {{- $href = printf "%s#%s" $href . }}
{{- end }} {{- end }}
{{- else }} {{- else }}
{{- if eq $page.Site.Params.link.errorlevel "warning" }} {{- if eq $errorlevel "warning" }}
{{- warnf "%q: link '%s' is not a page or a resource but linked anyways" $page.File.Filename .url }} {{- warnf "%q: link '%s' is not a page or a resource but linked anyways" $page.File.Filename .url }}
{{- else if eq $page.Site.Params.link.errorlevel "error" }} {{- else if eq $errorlevel "error" }}
{{- errorf "%q: link '%s' is not a page or a resource" $page.File.Filename .url }} {{- errorf "%q: link '%s' is not a page or a resource" $page.File.Filename .url }}
{{- end }} {{- end }}
{{- end }} {{- end }}

View file

@ -16,9 +16,10 @@
{{- $src = "" }} {{- $src = "" }}
{{- $spec = .Content }} {{- $spec = .Content }}
{{- else }} {{- else }}
{{- if eq $page.Site.Params.openapi.errorlevel "warning" }} {{- $errorlevel := or $page.Params.openapi.errorlevel $page.Site.Params.openapi.errorlevel }}
{{- if eq $errorlevel "warning" }}
{{- warnf "%q: OpenAPI spec link '%s' is not a resource but linked anyways" $page.File.Filename .url }} {{- warnf "%q: OpenAPI spec link '%s' is not a resource but linked anyways" $page.File.Filename .url }}
{{- else if eq $page.Site.Params.openapi.errorlevel "error" }} {{- else if eq $errorlevel "error" }}
{{- errorf "%q: OpenAPI spec link '%s' is not a resource" $page.File.Filename .url }} {{- errorf "%q: OpenAPI spec link '%s' is not a resource" $page.File.Filename .url }}
{{- end }} {{- end }}
{{- end }} {{- end }}