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
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"

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
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 -}}
{{- $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/" -}}
{{/* 1. Map /srv/configs/ -> content/configs/ */}}
{{- $mappedPath := replace $path "/srv/configs/" "content/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 -}}
{{- if fileExists $mappedPath -}}
{{- $content = readFile $mappedPath -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{/* 2. Map /srv/docs/private/ -> content/private/ */}}
{{- if not $found -}}
{{- $mappedPath = replace $path "/srv/docs/private/" "content/private/" -}}
{{- $mappedPath = strings.TrimLeft "/" $mappedPath -}}
{{- if fileExists $mappedPath -}}
{{- $content = readFile $mappedPath -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}