hugo-theme-relearn/layouts/partials/shortcodes/include.html

40 lines
No EOL
1.5 KiB
HTML

{{- $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/basics/migration#5180" $page.File.Filename }}
{{- 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 }}
{{- else }}
{{- if (fileExists .file) }}
{{- $content = .file | readFile }}
{{- else }}
{{- $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 }}
{{- else if eq $errorlevel "error" }}
{{- errorf "%q: included file '%s' is not a page, resource or accessible via file system" $page.File.Filename .file }}
{{- end }}
{{- end }}
{{- end }}
{{- $hideFirstHeading := .hidefirstheading | default false }}
{{- if eq (printf "%T" $hideFirstHeading) "string" }}
{{- $hideFirstHeading = (eq $hideFirstHeading "true") }}
{{- end }}
{{- if $content }}
{{- if $hideFirstHeading }}<div class="include hide-first-heading">
{{ end }}
{{- with $page }}
{{- $content | safeHTML }}
{{- end }}
{{- if $hideFirstHeading }}</div>{{ end }}
{{- end }}