include: DRY and guard File.Filename #1005 #1008

This commit is contained in:
Sören Weber 2025-02-07 20:09:04 +01:00
parent ada45be3f2
commit 8386020229
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
2 changed files with 10 additions and 12 deletions

View file

@ -1,23 +1,21 @@
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'include' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $page.File.Filename }}
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'include' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $filepath }}
{{- end }}
{{- $u := urls.Parse .file }}
{{- $path := strings.TrimPrefix "./" $u.Path }}
{{- $content := "" }}
{{- with or
($page.Page.GetPage $path)
($page.Page.GetPage (strings.TrimRight "/" $path))
($page.Page.Resources.Get $path)
(resources.Get $path)
}}
{{- $content = .Content }}
{{- $linkObject := or
(partial "_relearn/linkObject.gotmpl" (dict "url" .file "page" $page "searchGlobal" false "searchResource" false))
(partial "_relearn/linkObject.gotmpl" (dict "url" .file "page" $page "searchPage" false)) }}
{{- if $linkObject }}
{{- $content = $linkObject.Content }}
{{- else }}
{{- if (fileExists .file) }}
{{- $content = .file | readFile }}
{{- else }}
{{- $msg := printf "%q: include '%s' is not a page, a resource or a file" $page.File.Filename .file }}
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- $msg := printf "%q: include '%s' is not a page, a resource or a file" $filepath .file }}
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .file "page" $page "param" "include" "msg" $msg) }}
{{- end }}
{{- end }}

View file

@ -1 +1 @@
7.3.2+aaf0c707a2ee77896890c34b9d9990040aff448b
7.3.2+ada45be3f20e6f22357d406158e530921283623b