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

53 lines
2.0 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/" "" -}}
{{- $path = trim $path "/" -}}
{{/* Try multiple variations to find the Page */}}
{{/* CI environment flattens everything into content root, so "private/bazel/PRD.md" becomes "bazel/PRD.md" */}}
{{- $p := "" -}}
{{- $variations := slice $path (printf "private/%s" $path) (replace $path "private/" "") -}}
{{- range $v := $variations -}}
{{- if not $p }}{{ $p = $context.Site.GetPage $v }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" $v) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (strings.TrimSuffix ".md" $v) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (lower $v) }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (lower (strings.TrimSuffix ".md" $v)) }}{{ end -}}
{{- end -}}
{{- if $p -}}
{{- $p.Content -}}
{{- else -}}
{{/* Fallback to readFile - check multiple path variations */}}
{{- $found := false -}}
{{- $content := "" -}}
{{- $absPrivate := printf "/srv/docs/private/%s" (replace $path "private/" "") -}}
{{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "private/%s" $path) (printf "content/private/%s" $path) $absPrivate -}}
{{- 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 -}}