diff --git a/config/_default/hugo.toml b/config/_default/hugo.toml index 8c9257d..dcce9e4 100644 --- a/config/_default/hugo.toml +++ b/config/_default/hugo.toml @@ -49,3 +49,6 @@ enableGitInfo = true [[module.mounts]] source = "/srv/docs/private" target = "content/private" + [[module.mounts]] + source = "/srv/configs" + target = "configs" diff --git a/layouts/partials/include.html b/layouts/partials/include.html index 4354eb0..aa44de8 100644 --- a/layouts/partials/include.html +++ b/layouts/partials/include.html @@ -1,52 +1,57 @@ {{/* Partial: include.html - Handles including external Markdown files and rendering them. + Handles including external files (Markdown, YAML, etc.) and rendering or outputting 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" */}} +{{/* Map absolute paths to relative mount points */}} +{{- $originalPath := $path -}} +{{- $path = replace $path "/srv/docs/private/" "content/private/" -}} +{{- $path = replace $path "/srv/configs/" "configs/" -}} +{{- $path = strings.TrimLeft "/" $path -}} +{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}} {{- $p := "" -}} -{{- $variations := slice $path (printf "private/%s" $path) (replace $path "private/" "") -}} +{{- $content := "" -}} +{{- $found := false -}} -{{- 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 -}} +{{/* 1. Try to find a Hugo Page if it's Markdown */}} +{{- if $isMarkdown -}} + {{- $variations := slice $path (replace $path "content/" "") (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 -}} + {{- end -}} {{- end -}} {{- if $p -}} - {{- $p.Content -}} + {{- $content = $p.Content -}} + {{- $found = true -}} {{- 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 . -}} + {{/* 2. Fallback to readFile - check multiple path variations */}} + {{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "configs/%s" $path) -}} + {{- range $v := $pathsToTry -}} + {{- if and (not $found) (fileExists $v) -}} + {{- $content = readFile $v -}} {{- $found = true -}} {{- end -}} {{- end -}} +{{- end -}} - {{- if $found -}} +{{- if $found -}} + {{- if $isMarkdown -}} {{/* 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 -}} -
[Include Error: File "{{ $path }}" not found]
+ {{/* Output raw content for non-markdown files */}} + {{- $content | safeHTML -}} {{- end -}} +{{- else -}} + {{- warnf "Include file not found: %s" $originalPath -}} +[Include Error: File "{{ $originalPath }}" not found]
{{- end -}}