Files
hugo-framework/layouts/partials/include.html

45 lines
1.3 KiB
HTML

{{- $path := .path -}}
{{- $content := "" -}}
{{- $found := false -}}
{{- /* Handle /srv/ mapping to assets mount (trimming leading /srv/) */ -}}
{{- if strings.HasPrefix $path "/srv/" -}}
{{- $assetPath := strings.TrimPrefix "/srv/" $path -}}
{{- $res := resources.Get $assetPath -}}
{{- if $res -}}
{{- $content = $res.Content -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{- /* Handle /srv/docs/private/ mapping to content mount */ -}}
{{- if not $found -}}
{{- if strings.HasPrefix $path "/srv/docs/private/" -}}
{{- $pagePath := strings.TrimPrefix "/srv/docs/private/" $path -}}
{{- $p := site.GetPage (printf "private/%s" $pagePath) -}}
{{- if $p -}}
{{- $content = $p.RawContent -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* Handle relative or other paths by direct Page lookup */ -}}
{{- if not $found -}}
{{- $p := site.GetPage $path -}}
{{- if $p -}}
{{- $content = $p.RawContent -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{- if $found -}}
{{- /* Fallback manual frontmatter strip for assets that might have it */ -}}
{{- if findRE "^---" $content -}}
{{- $content = replaceRE "^(?s)---[\\s\\S]*?---[\\r\\n]*" "" $content -}}
{{- end -}}
{{- $content | safeHTML -}}
{{- else -}}
{{- warnf "WARN Include file not found: %s" $path -}}
{{- end -}}