From 9527cd17bb1201408284d6b2e99b705ea9bb8a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 29 Jan 2025 20:37:08 +0100 Subject: [PATCH] menu: DRY code #1002 --- layouts/partials/menu.html | 12 ------------ layouts/partials/menupermalink.gotmpl | 10 ++++++---- layouts/partials/meta.html | 10 ++++++---- layouts/partials/shortcodes/image.html | 5 +++-- layouts/partials/shortcodes/include.html | 5 +++-- layouts/partials/shortcodes/link.html | 9 ++++----- layouts/partials/shortcodes/openapi.html | 5 +++-- layouts/partials/version.txt | 2 +- 8 files changed, 26 insertions(+), 32 deletions(-) diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index 97830d7d6c..76711ca9d6 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -168,12 +168,6 @@ {{- with site.Home.GetPage (.Params.menuPageRef) }} {{- $url = partial "permalink.gotmpl" (dict "to" .) }} {{- $isCrosslink = true }} - {{- else }} - {{- if eq $errorlevel "warning" }} - {{- warnf "%q: menu link '%s' is not a page but linked anyways" $currentNode.File.Filename .Params.menuPageRef }} - {{- else if eq $errorlevel "error" }} - {{- errorf "%q: menu link '%s' is not a page" $currentNode.File.Filename .Params.menuPageRef }} - {{- end }} {{- end }} {{- else if .Params.menuUrl }} {{- $url = .Params.menuUrl }} @@ -185,12 +179,6 @@ {{- if isset site.Params "externallinktarget" }} {{- $target = site.Params.externalLinkTarget }} {{- end }} - {{- else }} - {{- if eq $errorlevel "warning" }} - {{- warnf "%q: local menu link '%s' was given by 'menuURL'; if it points to a page inside your Hugo site use 'menuPageRef' instead; link created anyways" $currentNode.File.Filename .Params.menuUrl }} - {{- else if eq $errorlevel "error" }} - {{- errorf "%q: local menu link '%s' was given by 'menuURL'; if it points to a page inside your Hugo site use 'menuPageRef' instead" $currentNode.File.Filename .Params.menuUrl }} - {{- end }} {{- end }} {{- end }} {{- $pre := partial "menu-pre.html" . }} diff --git a/layouts/partials/menupermalink.gotmpl b/layouts/partials/menupermalink.gotmpl index cdebec5903..9b6801996e 100644 --- a/layouts/partials/menupermalink.gotmpl +++ b/layouts/partials/menupermalink.gotmpl @@ -5,10 +5,11 @@ {{- with .Page }} {{- $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 "%q: menu link '%s' is not a page but linked anyways" $.page.File.Filename .PageRef }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: menu link '%s' is not a page" $.page.File.Filename .PageRef }} + {{- errorf $msg }} {{- end }} {{- end }} {{- else }} @@ -18,10 +19,11 @@ {{- if $u.IsAbs }} {{- 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 "%q: local menu link '%s' was given by 'URL'; if it points to a page inside your Hugo site use 'pageRef' instead; link created anyways" $.page.File.Filename . }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: local menu link '%s' was given by 'URL'; if it points to a page inside your Hugo site use 'pageRef' instead" $.page.File.Filename . }} + {{- errorf $msg }} {{- end }} {{- end }} {{- end }} diff --git a/layouts/partials/meta.html b/layouts/partials/meta.html index d8325b9419..f188829830 100644 --- a/layouts/partials/meta.html +++ b/layouts/partials/meta.html @@ -20,10 +20,11 @@ {{- with site.Home.GetPage (.Params.menuPageRef) }} {{- $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 "%q: menu link '%s' is not a page but linked anyways" .File.Filename .Params.menuPageRef }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: menu link '%s' is not a page" .File.Filename .Params.menuPageRef }} + {{- errorf $msg }} {{- end }} {{- end }} {{- else if .Params.menuUrl }} @@ -32,10 +33,11 @@ {{- if $u.IsAbs }} {{- 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 "%q: local menu link '%s' was given by 'menuURL'; if it points to a page inside your Hugo site use 'menuPageRef' instead; link created anyways" .File.Filename .Params.menuUrl }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: local menu link '%s' was given by 'menuURL'; if it points to a page inside your Hugo site use 'menuPageRef' instead" .File.Filename .Params.menuUrl }} + {{- errorf $msg }} {{- end }} {{- end }} {{- end }} diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html index a1644c629d..4245379f10 100644 --- a/layouts/partials/shortcodes/image.html +++ b/layouts/partials/shortcodes/image.html @@ -35,10 +35,11 @@ {{- 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 "%q: image '%s' is not a resource but linked anyways" $page.File.Filename .url }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: image '%s' is not a resource" $page.File.Filename .url }} + {{- errorf $msg }} {{- end }} {{- end }} {{- end }} diff --git a/layouts/partials/shortcodes/include.html b/layouts/partials/shortcodes/include.html index a613ad8299..f83525594c 100644 --- a/layouts/partials/shortcodes/include.html +++ b/layouts/partials/shortcodes/include.html @@ -18,10 +18,11 @@ {{- $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 "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }} + {{- warnf $msg }} {{- 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 $msg }} {{- end }} {{- end }} {{- end }} diff --git a/layouts/partials/shortcodes/link.html b/layouts/partials/shortcodes/link.html index 24c2074de1..e4b65779d7 100644 --- a/layouts/partials/shortcodes/link.html +++ b/layouts/partials/shortcodes/link.html @@ -13,7 +13,7 @@ {{- $attributes = $attributes | merge (dict "title" ($title | transform.HTMLEscape)) }} {{- $content := .content }} {{- $target := .target | default "" }} -{{- $u := urls.Parse .url -}} +{{- $u := urls.Parse .url }} {{- $href := $u.String }} {{- if $u.IsAbs }} {{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .url "page" $page "type" "link") $u.String }} @@ -79,10 +79,11 @@ {{- $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 "%q: link '%s' is not a page or a resource but linked anyways" $page.File.Filename .url }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: link '%s' is not a page or a resource" $page.File.Filename .url }} + {{- errorf $msg }} {{- end }} {{- end }} {{- end }} @@ -131,12 +132,10 @@ {{- else }} {{- $targetPath = .Path }} {{- end }} - {{- /* Set common message. */}} {{- $msg := printf "%q: heading ID %q not found in %q" $contentPath . $targetPath }} {{- if eq $targetPath $contentPath }} {{- $msg := printf "%q: heading ID %q not found" $contentPath . }} {{- end }} - {{- /* Throw warning or error. */}} {{- if eq $errorLevel "warning" }} {{- warnf $msg }} {{- else if eq $errorLevel "error" }} diff --git a/layouts/partials/shortcodes/openapi.html b/layouts/partials/shortcodes/openapi.html index 662a51c16a..3d6103081d 100644 --- a/layouts/partials/shortcodes/openapi.html +++ b/layouts/partials/shortcodes/openapi.html @@ -19,10 +19,11 @@ {{- $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 "%q: OpenAPI spec link '%s' is not a resource but linked anyways" $page.File.Filename .url }} + {{- warnf $msg }} {{- else if eq $errorlevel "error" }} - {{- errorf "%q: OpenAPI spec link '%s' is not a resource" $page.File.Filename .url }} + {{- errorf $msg }} {{- end }} {{- end }} {{- end }} diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index c6f084e0f1..ce1846861d 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.3.2+ba7e3b9b27ff1459815a786b6c6adb5686723b58 \ No newline at end of file +7.3.2+1205aa0448dcc4400e39e22e532ab4b62bb8b4c6 \ No newline at end of file