67 lines
2.3 KiB
HTML
67 lines
2.3 KiB
HTML
{{/*
|
|
Partial: include.html
|
|
Handles including external files (Markdown, YAML, etc.) and rendering or outputting them.
|
|
*/}}
|
|
{{- $path := .path -}}
|
|
{{- $context := .context -}}
|
|
|
|
{{- $originalPath := $path -}}
|
|
{{- $found := false -}}
|
|
{{- $content := "" -}}
|
|
{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}}
|
|
|
|
{{/* 1. Try absolute path directly (enabled by security settings in hugo.toml) */}}
|
|
{{- if fileExists $path -}}
|
|
{{- $content = readFile $path -}}
|
|
{{- $found = true -}}
|
|
{{- end -}}
|
|
|
|
{{/* 2. Map absolute paths to relative mount points if not found directly */}}
|
|
{{- if not $found -}}
|
|
{{- $mappedPath := replace $path "/srv/docs/private/" "content/private/" -}}
|
|
{{- $mappedPath = replace $mappedPath "/srv/configs/" "configs/" -}}
|
|
{{- $mappedPath = strings.TrimLeft "/" $mappedPath -}}
|
|
|
|
{{- $p := "" -}}
|
|
|
|
{{/* Try to find a Hugo Page if it's Markdown */}}
|
|
{{- if $isMarkdown -}}
|
|
{{- $variations := slice $mappedPath (replace $mappedPath "content/" "") (replace $mappedPath "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 -}}
|
|
{{/* Fallback to readFile - check multiple path variations */}}
|
|
{{- $pathsToTry := slice $mappedPath (printf "content/%s" $mappedPath) (printf "configs/%s" $mappedPath) -}}
|
|
{{- range $v := $pathsToTry -}}
|
|
{{- if and (not $found) (fileExists $v) -}}
|
|
{{- $content = readFile $v -}}
|
|
{{- $found = true -}}
|
|
{{- end -}}
|
|
{{- 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 -}}
|