mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-31 00:47:13 +00:00
link: add ignore list to checker to skip certain URLs #971
This commit is contained in:
parent
239ae4ed64
commit
df03dac58f
14 changed files with 75 additions and 54 deletions
|
@ -111,6 +111,17 @@ disableGeneratorVersion = false
|
|||
# may not function correctly anymore.
|
||||
disableRandomIds = false
|
||||
|
||||
# Conditionally ignore errorlevel settings
|
||||
# Default: []
|
||||
# The theme supports checking referenced address (e.g. with
|
||||
# link.errorlevel, image.errorlevel, etc. see below). Sometimes checks lead
|
||||
# to console output due to false negatives. You can turn off the checks
|
||||
# for individual referenced addresses by defining regular expressions here.
|
||||
# The referenced address will be checked against all regexes of this array.
|
||||
# If it matches at least one, no output will be written to the console.
|
||||
# This array can be expanded in the page's frontmatter.
|
||||
errorignore = []
|
||||
|
||||
# Additional code dependencies.
|
||||
# Default: See hugo.toml of the theme
|
||||
# The theme provides a mechanism to load further JavaScript and CSS
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
+++
|
||||
categories = ["howto"]
|
||||
description = "What options are available for links and images"
|
||||
frontmatter = ["externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
options = ["externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
frontmatter = ["errorignore", "externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
options = ["errorignore", "externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
title = "Linking"
|
||||
weight = 3
|
||||
+++
|
||||
|
@ -31,3 +31,11 @@ Link warnings are also available for the [include](shortcodes/include#enabling-l
|
|||
link.errorlevel = 'warning'
|
||||
image.errorlevel = 'warning'
|
||||
{{< /multiconfig >}}
|
||||
|
||||
### Ignoring False Negatives
|
||||
|
||||
{{% badge style="cyan" icon="gears" title=" " %}}Option{{% /badge %}} {{% badge style="green" icon="fa-fw fab fa-markdown" title=" " %}}Front Matter{{% /badge %}} In case you want to use link warnings but are bothered by false negatives, you can configure an ignore list of regular expressions. The referenced address will be checked against all regexes of this list. If the address matches at least one regex, no output will be written to the console. The check uses [Hugo's `findRE` function](https://gohugo.io/functions/strings/findre/).
|
||||
|
||||
{{< multiconfig >}}
|
||||
errorignore = [ '^/authoring/', '^/configuration/' ]
|
||||
{{< /multiconfig >}}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
+++
|
||||
categories = ["howto"]
|
||||
description = "What options are available for links and images"
|
||||
frontmatter = ["externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
options = ["externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
frontmatter = ["errorignore", "externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
options = ["errorignore", "externalLinkTarget", "image.errorlevel", "link.errorlevel"]
|
||||
title = "Linking"
|
||||
weight = 3
|
||||
+++
|
||||
|
|
|
@ -36,6 +36,21 @@ type = ''
|
|||
# Relearn Theme
|
||||
# These options are specific to the Relearn theme.
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# General
|
||||
# These options are defining general, non visual behavior.
|
||||
|
||||
# Conditionally ignore errorlevel settings
|
||||
# Default: []
|
||||
# The theme supports checking referenced address (e.g. with
|
||||
# link.errorlevel, image.errorlevel, etc. see below). Sometimes checks lead
|
||||
# to console output due to false negatives. You can turn off the checks
|
||||
# for individual referenced addresses by defining regular expressions here.
|
||||
# The referenced address will be checked against all regexes of this array.
|
||||
# If it matches at least one, no output will be written to the console.
|
||||
# This array can be expanded globally in your site's hugo.toml.
|
||||
errorignore = []
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# Topbar
|
||||
# These options modify the topbar appearance.
|
||||
|
|
|
@ -16,8 +16,8 @@ weight = -3
|
|||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme supports the new [`markdown` output format](configuration/sitemanagement/outputformats/#markdown-support) which behaves similar in configuration as the `print` output format but allows the Markdown source of a page to be viewed.
|
||||
|
||||
You can see this in action on the above linked page, accessible by clicking the topbar button.
|
||||
You can see this in action on the above linked page, accessible by clicking the {{% button style="transparent" icon="fa-fw fab fa-markdown" %}}{{% /button %}} topbar button.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Keyboard support for code blocks was improved so the _copy to clipboard_ button is now reachable by <kbd>TAB</kbd> if `disableHoverBlockCopyToClipBoard=false` was set in the `hugo.toml`.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Futher accessibility impovements were made for the _anchor_, _copy to clipboard_ and _mermaid reset_ functionality by using a HTML `button` instead of a `span`.
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Further accessibility improvements were made for the _anchor_, _copy to clipboard_ and _mermaid reset_ functionality by using a HTML `button` instead of a `span`.
|
||||
|
|
|
@ -10,10 +10,12 @@ weight = -4
|
|||
|
||||
### New
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} If `link.errorlevel` is configured, now also the `pageRef` of a [Hugo menu item](https://gohugo.io/content-management/menus/) and the `menuPageRef` in a page's front matter will be checked for existence.
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} If [`link.errorlevel` is configured](authoring/frontmatter/linking/#enabling-link-and-image-link-warnings), now also the `pageRef` of a [Hugo menu item](https://gohugo.io/content-management/menus/) and the `menuPageRef` in a [page's front matter](configuration/sidebar/menus/#displaying-arbitrary-links-in-a-page-menu) will be checked for existence.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} You can now [configure an ignore list](authoring/frontmatter/linking/#ignoring-false-negatives) of addresses that should be ignored if an errorlevel test fails. This is configured by setting `errorignore=[]` in your `hugo.toml`. This helps to remove false negatives from the output while still benefitting from the check for all other addresses.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme supports the new [`source` output format](configuration/sitemanagement/outputformats/#source-support) which behaves similar in configuration as the `markdown` output format but allows the original Markdown source including the front matter of a page to be viewed.
|
||||
|
||||
You can see this in action on the above linked page, accessible by clicking the topbar button.
|
||||
You can see this in action on the above linked page, accessible by clicking the {{% button style="transparent" icon="file-code" %}}{{% /button %}} topbar button.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Table headers are sticky now.
|
||||
|
|
20
layouts/partials/_relearn/urlErrorReport.gotmpl
Normal file
20
layouts/partials/_relearn/urlErrorReport.gotmpl
Normal file
|
@ -0,0 +1,20 @@
|
|||
{{- $pageParam := index .page.Params .param }}
|
||||
{{- $siteParam := index .page.Site.Params .param }}
|
||||
{{- $errorlevel := or (and $pageParam $pageParam.errorlevel) (and $siteParam $siteParam.errorlevel) }}
|
||||
{{- $errorignore := slice | append (.page.Params.errorignore | default slice ) | append (.page.Site.Params.errorignore | default slice ) }}
|
||||
{{- if and (eq $errorlevel "warning") (partial "inline/show-error" (dict "errorignore" $errorignore "url" .url)) }}
|
||||
{{- warnf .msg }}
|
||||
{{- else if and (eq $errorlevel "error") (partial "inline/show-error" (dict "errorignore" $errorignore "url" .url)) }}
|
||||
{{- errorf .msg }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "partials/inline/show-error" }}
|
||||
{{- $ret := true }}
|
||||
{{- range .errorignore }}
|
||||
{{- if findRE . $.url 1 }}
|
||||
{{- $ret = false }}
|
||||
{{- break }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- return $ret }}
|
||||
{{- end }}
|
|
@ -6,11 +6,7 @@
|
|||
{{- $url = partial "permalink.gotmpl" (dict "to" .) }}
|
||||
{{- else }}
|
||||
{{- $msg := printf "%q: config menu link '%s' is not a page" $.page.File.Filename .PageRef }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .PageRef "page" $.page "param" "link" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- with .URL }}
|
||||
|
@ -20,11 +16,7 @@
|
|||
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" $url "page" $.page "type" "menu link") $u.String }}
|
||||
{{- else }}
|
||||
{{- $msg := printf "%q: config menu link '%s' given by 'URL' is not verified; if it is a page use 'PageRef' instead" $.page.File.Filename . }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" . "page" $.page "param" "link" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
|
@ -21,11 +21,7 @@
|
|||
{{- $url = partial "permalink.gotmpl" (dict "to" .) }}
|
||||
{{- else }}
|
||||
{{- $msg := printf "%q: front matter crosslink '%s' is not a page" .File.Filename .Params.menuPageRef }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .Params.menuPageRef "page" . "param" "link" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- else if .Params.menuUrl }}
|
||||
{{- $url = .Params.menuUrl }}
|
||||
|
@ -34,11 +30,7 @@
|
|||
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" $url "page" . "type" "menu link") $u.String }}
|
||||
{{- else }}
|
||||
{{- $msg := printf "%q: front matter crosslink '%s' given by 'menuURL' is not verified; if it is a page use 'menuPageRef' instead" .File.Filename .Params.menuUrl }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .Params.menuUrl "page" . "param" "link" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $url }}
|
||||
|
|
|
@ -34,13 +34,8 @@
|
|||
{{- $src = printf "%s#%s" $src . }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- $errorlevel := or $page.Params.image.errorlevel $page.Site.Params.image.errorlevel }}
|
||||
{{- $msg := printf "%q: image '%s' is not a resource" $page.File.Filename .url }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .url "page" $page "param" "image" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if $u.RawQuery }}
|
||||
|
|
|
@ -17,13 +17,8 @@
|
|||
{{- if (fileExists .file) }}
|
||||
{{- $content = .file | readFile }}
|
||||
{{- else }}
|
||||
{{- $errorlevel := or $page.Params.include.errorlevel $page.Site.Params.include.errorlevel }}
|
||||
{{- $msg := printf "%q: include '%s' is not a page, a resource or a file" $page.File.Filename .file }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .file "page" $page "param" "include" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $hideFirstHeading := .hidefirstheading | default false }}
|
||||
|
|
|
@ -75,16 +75,12 @@
|
|||
"parsedURL" $u
|
||||
"renderHookName" "link"
|
||||
}}
|
||||
{{- partial "inline/h-rh-l/validate-fragment.html" $ctx }}
|
||||
{{- partial "inline/validate-fragment.html" $ctx }}
|
||||
{{- $href = printf "%s#%s" $href . }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- $msg := printf "%q: link '%s' is not a page or a resource" $page.File.Filename .url }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .url "page" $page "param" "link" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $attributes = $attributes | merge (dict "href" $href) -}}
|
||||
|
@ -95,7 +91,7 @@
|
|||
{{- end }}
|
||||
{{- end }}>{{ $content | safeHTML }}</a>
|
||||
|
||||
{{- define "partials/inline/h-rh-l/validate-fragment.html" }}
|
||||
{{- define "partials/inline/validate-fragment.html" }}
|
||||
{{- /*
|
||||
Validates the fragment portion of a link destination.
|
||||
|
||||
|
|
|
@ -18,13 +18,8 @@
|
|||
{{- $src = "" }}
|
||||
{{- $spec = .Content }}
|
||||
{{- else }}
|
||||
{{- $errorlevel := or $page.Params.openapi.errorlevel $page.Site.Params.openapi.errorlevel }}
|
||||
{{- $msg := printf "%q: OpenAPI spec '%s' is not a resource" $page.File.Filename .src }}
|
||||
{{- if eq $errorlevel "warning" }}
|
||||
{{- warnf $msg }}
|
||||
{{- else if eq $errorlevel "error" }}
|
||||
{{- errorf $msg }}
|
||||
{{- end }}
|
||||
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .src "page" $page "param" "openapi" "msg" $msg) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- with $page -}}
|
||||
|
|
|
@ -1 +1 @@
|
|||
7.3.2+9527cd17bb1201408284d6b2e99b705ea9bb8a8b
|
||||
7.3.2+239ae4ed64e9976ba7071aa19f4e4f31904742d6
|
Loading…
Add table
Reference in a new issue