fixing mount points and updating the include

partial

1. Mounted Configuration Directory: Added /srv/configs as a mount point in
      /srv/dev/hugo/wiki/config/_default/hugo.toml. This allows Hugo's readFile and fileExists functions to
      access your Docker Compose and other configuration files within the virtual filesystem.
2. Improved include Partial: Rewrote /srv/dev/hugo/wiki/layouts/partials/include.html with the following
      enhancements:
    * Path Mapping: It now automatically maps absolute paths like /srv/configs/... to the new configs/ mount
         and /srv/docs/private/... to the existing content/private/ mount.
    * Raw Content Support: If the included file is not a Markdown file (e.g., .yaml, .env, .sh), it now
         outputs the raw content instead of attempting to render it as Markdown. This ensures that your Docker
         Compose files are included exactly as they are when wrapped in a code block.
    * Robust Lookups: Added better path variation checking to handle both absolute and relative paths more
         gracefully.
This commit is contained in:
2026-03-28 23:27:12 +00:00
parent cab796c749
commit 98a0e1eda9
2 changed files with 35 additions and 27 deletions

View File

@@ -49,3 +49,6 @@ enableGitInfo = true
[[module.mounts]] [[module.mounts]]
source = "/srv/docs/private" source = "/srv/docs/private"
target = "content/private" target = "content/private"
[[module.mounts]]
source = "/srv/configs"
target = "configs"

View File

@@ -1,52 +1,57 @@
{{/* {{/*
Partial: include.html 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 -}} {{- $path := .path -}}
{{- $context := .context -}} {{- $context := .context -}}
{{/* Map absolute private paths to the relative content mount point */}} {{/* Map absolute paths to relative mount points */}}
{{- $path = replace $path "/srv/docs/private/" "" -}} {{- $originalPath := $path -}}
{{- $path = trim $path "/" -}} {{- $path = replace $path "/srv/docs/private/" "content/private/" -}}
{{- $path = replace $path "/srv/configs/" "configs/" -}}
{{/* Try multiple variations to find the Page */}} {{- $path = strings.TrimLeft "/" $path -}}
{{/* CI environment flattens everything into content root, so "private/bazel/PRD.md" becomes "bazel/PRD.md" */}}
{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}}
{{- $p := "" -}} {{- $p := "" -}}
{{- $variations := slice $path (printf "private/%s" $path) (replace $path "private/" "") -}} {{- $content := "" -}}
{{- $found := false -}}
{{- range $v := $variations -}} {{/* 1. Try to find a Hugo Page if it's Markdown */}}
{{- if not $p }}{{ $p = $context.Site.GetPage $v }}{{ end -}} {{- if $isMarkdown -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" $v) }}{{ end -}} {{- $variations := slice $path (replace $path "content/" "") (replace $path "private/" "") -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (strings.TrimSuffix ".md" $v) }}{{ end -}} {{- range $v := $variations -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (lower $v) }}{{ end -}} {{- if not $p }}{{ $p = $context.Site.GetPage $v }}{{ end -}}
{{- if not $p }}{{ $p = $context.Site.GetPage (lower (strings.TrimSuffix ".md" $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 -}} {{- end -}}
{{- if $p -}} {{- if $p -}}
{{- $p.Content -}} {{- $content = $p.Content -}}
{{- $found = true -}}
{{- else -}} {{- else -}}
{{/* Fallback to readFile - check multiple path variations */}} {{/* 2. Fallback to readFile - check multiple path variations */}}
{{- $found := false -}} {{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "configs/%s" $path) -}}
{{- $content := "" -}} {{- range $v := $pathsToTry -}}
{{- $absPrivate := printf "/srv/docs/private/%s" (replace $path "private/" "") -}} {{- if and (not $found) (fileExists $v) -}}
{{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "private/%s" $path) (printf "content/private/%s" $path) $absPrivate -}} {{- $content = readFile $v -}}
{{- range $pathsToTry -}}
{{- if and (not $found) (fileExists .) -}}
{{- $content = readFile . -}}
{{- $found = true -}} {{- $found = true -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}}
{{- if $found -}} {{- if $found -}}
{{- if $isMarkdown -}}
{{/* Strip frontmatter if it exists */}} {{/* Strip frontmatter if it exists */}}
{{- if (findRE "^---" $content) -}} {{- if (findRE "^---" $content) -}}
{{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}} {{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}}
{{- end -}} {{- end -}}
{{- $context.RenderString $content -}} {{- $context.RenderString $content -}}
{{- else -}} {{- else -}}
{{- warnf "Include file not found: %s" $path -}} {{/* Output raw content for non-markdown files */}}
<p class="text-red-500 font-bold">[Include Error: File "{{ $path }}" not found]</p> {{- $content | safeHTML -}}
{{- end -}} {{- end -}}
{{- else -}}
{{- warnf "Include file not found: %s" $originalPath -}}
<p class="text-red-500 font-bold">[Include Error: File "{{ $originalPath }}" not found]</p>
{{- end -}} {{- end -}}