another test fix for includes

This commit is contained in:
2026-03-28 23:47:44 +00:00
parent 76a74bfd04
commit b7bb744d2f
4 changed files with 20 additions and 35 deletions

View File

@@ -42,6 +42,7 @@ enableGitInfo = true
endLevel = 3 endLevel = 3
ordered = false ordered = false
startLevel = 2 startLevel = 2
[module] [module]
[[module.mounts]] [[module.mounts]]
source = "content" source = "content"
@@ -51,7 +52,4 @@ enableGitInfo = true
target = "content/private" target = "content/private"
[[module.mounts]] [[module.mounts]]
source = "/srv/configs" source = "/srv/configs"
target = "configs" target = "content/configs"
[security]
[security.funcs]
readFile = ["^/srv/configs/.*", "^/srv/docs/private/.*"]

View 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/.*"]

3
hugo.toml Normal file
View File

@@ -0,0 +1,3 @@
[security]
[security.funcs]
readFile = [".*"]

View File

@@ -1,6 +1,6 @@
{{/* {{/*
Partial: include.html Partial: include.html
Handles including external files (Markdown, YAML, etc.) and rendering or outputting them. Simple include using content/configs mount
*/}} */}}
{{- $path := .path -}} {{- $path := .path -}}
{{- $context := .context -}} {{- $context := .context -}}
@@ -10,42 +10,22 @@
{{- $content := "" -}} {{- $content := "" -}}
{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}} {{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}}
{{/* 1. Try absolute path directly (enabled by security settings in hugo.toml) */}} {{/* 1. Map /srv/configs/ -> content/configs/ */}}
{{- if fileExists $path -}} {{- $mappedPath := replace $path "/srv/configs/" "content/configs/" -}}
{{- $content = readFile $path -}} {{- $mappedPath = strings.TrimLeft "/" $mappedPath -}}
{{- if fileExists $mappedPath -}}
{{- $content = readFile $mappedPath -}}
{{- $found = true -}} {{- $found = true -}}
{{- end -}} {{- end -}}
{{/* 2. Map absolute paths to relative mount points if not found directly */}} {{/* 2. Map /srv/docs/private/ -> content/private/ */}}
{{- if not $found -}} {{- if not $found -}}
{{- $mappedPath := replace $path "/srv/docs/private/" "content/private/" -}} {{- $mappedPath = replace $path "/srv/docs/private/" "content/private/" -}}
{{- $mappedPath = replace $mappedPath "/srv/configs/" "configs/" -}}
{{- $mappedPath = strings.TrimLeft "/" $mappedPath -}} {{- $mappedPath = strings.TrimLeft "/" $mappedPath -}}
{{- if fileExists $mappedPath -}}
{{- $p := "" -}} {{- $content = readFile $mappedPath -}}
{{/* 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 -}} {{- $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 -}}