another test fix for includes
This commit is contained in:
@@ -42,6 +42,7 @@ enableGitInfo = true
|
||||
endLevel = 3
|
||||
ordered = false
|
||||
startLevel = 2
|
||||
|
||||
[module]
|
||||
[[module.mounts]]
|
||||
source = "content"
|
||||
@@ -51,7 +52,4 @@ enableGitInfo = true
|
||||
target = "content/private"
|
||||
[[module.mounts]]
|
||||
source = "/srv/configs"
|
||||
target = "configs"
|
||||
[security]
|
||||
[security.funcs]
|
||||
readFile = ["^/srv/configs/.*", "^/srv/docs/private/.*"]
|
||||
target = "content/configs"
|
||||
|
||||
4
config/_default/security.toml
Normal file
4
config/_default/security.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[funcs]
|
||||
readFile = ["^/srv/configs/.*", "^/srv/docs/private/.*", "^static/.*"]
|
||||
os.Stat = ["^/srv/configs/.*", "^/srv/docs/private/.*", "^static/.*"]
|
||||
os.ReadDir = ["^/srv/configs/.*", "^/srv/docs/private/.*", "^static/.*"]
|
||||
@@ -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