35 lines
1.2 KiB
HTML
35 lines
1.2 KiB
HTML
{{/*
|
|
Partial: include.html
|
|
Handles including external Markdown files and rendering them.
|
|
Parameters:
|
|
- context: The Page context (required for RenderString/GetPage)
|
|
- path: Path to the file, relative to the project root or content root
|
|
*/}}
|
|
{{- $path := .path -}}
|
|
{{- $context := .context -}}
|
|
|
|
{{/* Map absolute private paths to the relative content mount point */}}
|
|
{{- $path = replace $path "/srv/docs/private/" "private/" -}}
|
|
|
|
{{/* Remove leading slash if any (GetPage prefers relative-to-content paths) */}}
|
|
{{- $path = trim $path "/" -}}
|
|
|
|
{{/* Try to get as a Page first (supports mounts and already handles frontmatter) */}}
|
|
{{- $p := $context.Site.GetPage $path -}}
|
|
{{- if $p -}}
|
|
{{- $p.Content -}}
|
|
{{- else -}}
|
|
{{/* Fallback to readFile for non-page files */}}
|
|
{{- if fileExists $path -}}
|
|
{{- $content := readFile $path -}}
|
|
{{/* 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 -}}
|