Files
hugo-framework/layouts/partials/include.html
2026-03-28 04:59:39 +00:00

47 lines
1.8 KiB
HTML

{{/*
Partial: include.html
Handles including external Markdown files and rendering them.
*/}}
{{- $path := .path -}}
{{- $context := .context -}}
{{/* Map absolute private paths to the relative content mount point */}}
{{- $path = replace $path "/srv/docs/private/" "private/" -}}
{{- $path = trim $path "/" -}}
{{/* Try multiple variations to find the Page */}}
{{- $p := $context.Site.GetPage $path -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" $path) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (strings.TrimSuffix ".md" $path) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" (strings.TrimSuffix ".md" $path)) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (lower $path) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (lower (strings.TrimSuffix ".md" $path)) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" (lower (strings.TrimSuffix ".md" $path))) }}{{ end -}}
{{- if $p -}}
{{- $p.Content -}}
{{- else -}}
{{/* Fallback to readFile - check multiple path variations */}}
{{- $found := false -}}
{{- $content := "" -}}
{{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "/%s" $path) -}}
{{- range $pathsToTry -}}
{{- if and (not $found) (fileExists .) -}}
{{- $content = readFile . -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{- if $found -}}
{{/* Strip frontmatter if it exists */}}
{{- if (findRE "^---" $content) -}}
{{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}}
{{- end -}}
{{- $context.RenderString $content -}}
{{- else -}}
{{- warnf "Include file not found: %s" $path -}}
<p class="text-red-500 font-bold">[Include Error: File "{{ $path }}" not found]</p>
{{- end -}}
{{- end -}}