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]]
|
[[module.mounts]]
|
||||||
source = "/srv/configs"
|
source = "/srv/configs"
|
||||||
target = "configs"
|
target = "configs"
|
||||||
|
[security]
|
||||||
|
[security.funcs]
|
||||||
|
readFile = ["^/srv/configs/.*", "^/srv/docs/private/.*"]
|
||||||
|
|||||||
@@ -5,37 +5,46 @@
|
|||||||
{{- $path := .path -}}
|
{{- $path := .path -}}
|
||||||
{{- $context := .context -}}
|
{{- $context := .context -}}
|
||||||
|
|
||||||
{{/* Map absolute paths to relative mount points */}}
|
|
||||||
{{- $originalPath := $path -}}
|
{{- $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 -}}
|
{{- $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 $isMarkdown -}}
|
{{- if fileExists $path -}}
|
||||||
{{- $variations := slice $path (replace $path "content/" "") (replace $path "private/" "") -}}
|
{{- $content = readFile $path -}}
|
||||||
{{- range $v := $variations -}}
|
{{- $found = true -}}
|
||||||
{{- 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 -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- if $p -}}
|
{{/* 2. Map absolute paths to relative mount points if not found directly */}}
|
||||||
{{- $content = $p.Content -}}
|
{{- if not $found -}}
|
||||||
{{- $found = true -}}
|
{{- $mappedPath := replace $path "/srv/docs/private/" "content/private/" -}}
|
||||||
{{- else -}}
|
{{- $mappedPath = replace $mappedPath "/srv/configs/" "configs/" -}}
|
||||||
{{/* 2. Fallback to readFile - check multiple path variations */}}
|
{{- $mappedPath = strings.TrimLeft "/" $mappedPath -}}
|
||||||
{{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "configs/%s" $path) -}}
|
|
||||||
{{- range $v := $pathsToTry -}}
|
{{- $p := "" -}}
|
||||||
{{- if and (not $found) (fileExists $v) -}}
|
|
||||||
{{- $content = readFile $v -}}
|
{{/* Try to find a Hugo Page if it's Markdown */}}
|
||||||
{{- $found = true -}}
|
{{- 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 -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user