Files
hugo-framework/layouts/partials/include.html
wompmacho 98a0e1eda9 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.
2026-03-28 23:27:12 +00:00

58 lines
2.0 KiB
HTML

{{/*
Partial: include.html
Handles including external files (Markdown, YAML, etc.) and rendering or outputting them.
*/}}
{{- $path := .path -}}
{{- $context := .context -}}
{{/* 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 := "" -}}
{{- $content := "" -}}
{{- $found := false -}}
{{/* 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 -}}
{{- $content = $p.Content -}}
{{- $found = true -}}
{{- else -}}
{{/* 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 $isMarkdown -}}
{{/* Strip frontmatter if it exists */}}
{{- if (findRE "^---" $content) -}}
{{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}}
{{- end -}}
{{- $context.RenderString $content -}}
{{- else -}}
{{/* Output raw content for non-markdown files */}}
{{- $content | safeHTML -}}
{{- end -}}
{{- else -}}
{{- warnf "Include file not found: %s" $originalPath -}}
<p class="text-red-500 font-bold">[Include Error: File "{{ $originalPath }}" not found]</p>
{{- end -}}