From b7bb744d2f4502c5cf2c83ac10e65d86b6d5fa41 Mon Sep 17 00:00:00 2001 From: wompmacho Date: Sat, 28 Mar 2026 23:47:44 +0000 Subject: [PATCH] another test fix for includes --- config/_default/hugo.toml | 6 ++--- config/_default/security.toml | 4 ++++ hugo.toml | 3 +++ layouts/partials/include.html | 42 +++++++++-------------------------- 4 files changed, 20 insertions(+), 35 deletions(-) create mode 100644 config/_default/security.toml create mode 100644 hugo.toml diff --git a/config/_default/hugo.toml b/config/_default/hugo.toml index 7c091d3..c7ede2b 100644 --- a/config/_default/hugo.toml +++ b/config/_default/hugo.toml @@ -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" diff --git a/config/_default/security.toml b/config/_default/security.toml new file mode 100644 index 0000000..07fa341 --- /dev/null +++ b/config/_default/security.toml @@ -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/.*"] diff --git a/hugo.toml b/hugo.toml new file mode 100644 index 0000000..9b29bbd --- /dev/null +++ b/hugo.toml @@ -0,0 +1,3 @@ +[security] + [security.funcs] + readFile = [".*"] diff --git a/layouts/partials/include.html b/layouts/partials/include.html index bf1de0a..0ec0207 100644 --- a/layouts/partials/include.html +++ b/layouts/partials/include.html @@ -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 -}}