another test fix for includes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{{/*
|
||||
Partial: include.html
|
||||
Handles including external files (Markdown, YAML, etc.) and rendering or outputting them.
|
||||
Simple include using content/configs mount
|
||||
*/}}
|
||||
{{- $path := .path -}}
|
||||
{{- $context := .context -}}
|
||||
@@ -10,42 +10,22 @@
|
||||
{{- $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 -}}
|
||||
{{/* 1. Map /srv/configs/ -> content/configs/ */}}
|
||||
{{- $mappedPath := replace $path "/srv/configs/" "content/configs/" -}}
|
||||
{{- $mappedPath = strings.TrimLeft "/" $mappedPath -}}
|
||||
|
||||
{{- if fileExists $mappedPath -}}
|
||||
{{- $content = readFile $mappedPath -}}
|
||||
{{- $found = true -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* 2. Map absolute paths to relative mount points if not found directly */}}
|
||||
{{/* 2. Map /srv/docs/private/ -> content/private/ */}}
|
||||
{{- if not $found -}}
|
||||
{{- $mappedPath := replace $path "/srv/docs/private/" "content/private/" -}}
|
||||
{{- $mappedPath = replace $mappedPath "/srv/configs/" "configs/" -}}
|
||||
{{- $mappedPath = replace $path "/srv/docs/private/" "content/private/" -}}
|
||||
{{- $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 -}}
|
||||
{{- if fileExists $mappedPath -}}
|
||||
{{- $content = readFile $mappedPath -}}
|
||||
{{- $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 -}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user