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 }} {{- $page := .page }}
{{- if and (not $page) .context }} {{- if and (not $page) .context }}
{{- $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 }} {{- end }}
{{- $u := urls.Parse .file }}
{{- $path := strings.TrimPrefix "./" $u.Path }}
{{- $content := "" }} {{- $content := "" }}
{{- with or {{- $linkObject := or
($page.Page.GetPage $path) (partial "_relearn/linkObject.gotmpl" (dict "url" .file "page" $page "searchGlobal" false "searchResource" false))
($page.Page.GetPage (strings.TrimRight "/" $path)) (partial "_relearn/linkObject.gotmpl" (dict "url" .file "page" $page "searchPage" false)) }}
($page.Page.Resources.Get $path) {{- if $linkObject }}
(resources.Get $path) {{- $content = $linkObject.Content }}
}}
{{- $content = .Content }}
{{- else }} {{- else }}
{{- if (fileExists .file) }} {{- if (fileExists .file) }}
{{- $content = .file | readFile }} {{- $content = .file | readFile }}
{{- else }} {{- 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) }} {{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .file "page" $page "param" "include" "msg" $msg) }}
{{- end }} {{- end }}
{{- end }} {{- end }}

View file

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