diff --git a/config/_default/hugo.toml b/config/_default/hugo.toml index dcce9e4..7c091d3 100644 --- a/config/_default/hugo.toml +++ b/config/_default/hugo.toml @@ -52,3 +52,6 @@ enableGitInfo = true [[module.mounts]] source = "/srv/configs" target = "configs" +[security] + [security.funcs] + readFile = ["^/srv/configs/.*", "^/srv/docs/private/.*"] diff --git a/layouts/partials/include.html b/layouts/partials/include.html index aa44de8..bf1de0a 100644 --- a/layouts/partials/include.html +++ b/layouts/partials/include.html @@ -5,37 +5,46 @@ {{- $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 -}} +{{- $content := "" -}} +{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}} -{{/* 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 -}} +{{/* 1. Try absolute path directly (enabled by security settings in hugo.toml) */}} +{{- if fileExists $path -}} + {{- $content = readFile $path -}} + {{- $found = true -}} {{- 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 -}} +{{/* 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 -}}