update to allow security on hugo to build in config in another dir
This commit is contained in:
@@ -52,3 +52,6 @@ enableGitInfo = true
|
||||
[[module.mounts]]
|
||||
source = "/srv/configs"
|
||||
target = "configs"
|
||||
[security]
|
||||
[security.funcs]
|
||||
readFile = ["^/srv/configs/.*", "^/srv/docs/private/.*"]
|
||||
|
||||
@@ -5,20 +5,28 @@
|
||||
{{- $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 */}}
|
||||
{{/* 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 $path (replace $path "content/" "") (replace $path "private/" "") -}}
|
||||
{{- $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 -}}
|
||||
@@ -30,8 +38,8 @@
|
||||
{{- $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) -}}
|
||||
{{/* 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 -}}
|
||||
@@ -39,6 +47,7 @@
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $found -}}
|
||||
{{- if $isMarkdown -}}
|
||||
|
||||
Reference in New Issue
Block a user