From 8a57cbf8a51eed9998d3b88edc17ec4979f2ad0c Mon Sep 17 00:00:00 2001 From: wompmacho Date: Sat, 28 Mar 2026 04:59:39 +0000 Subject: [PATCH] test include again --- layouts/partials/include.html | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/layouts/partials/include.html b/layouts/partials/include.html index 54f5980..d72f621 100644 --- a/layouts/partials/include.html +++ b/layouts/partials/include.html @@ -1,27 +1,39 @@ {{/* Partial: include.html Handles including external Markdown files and rendering them. - Parameters: - - context: The Page context (required for RenderString/GetPage) - - path: Path to the file, relative to the project root or content root */}} {{- $path := .path -}} {{- $context := .context -}} {{/* Map absolute private paths to the relative content mount point */}} {{- $path = replace $path "/srv/docs/private/" "private/" -}} - -{{/* Remove leading slash if any (GetPage prefers relative-to-content paths) */}} {{- $path = trim $path "/" -}} -{{/* Try to get as a Page first (supports mounts and already handles frontmatter) */}} +{{/* Try multiple variations to find the Page */}} {{- $p := $context.Site.GetPage $path -}} +{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" $path) }}{{ end -}} +{{- if not $p }}{{ $p = $context.Site.GetPage (strings.TrimSuffix ".md" $path) }}{{ end -}} +{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" (strings.TrimSuffix ".md" $path)) }}{{ end -}} +{{- if not $p }}{{ $p = $context.Site.GetPage (lower $path) }}{{ end -}} +{{- if not $p }}{{ $p = $context.Site.GetPage (lower (strings.TrimSuffix ".md" $path)) }}{{ end -}} +{{- if not $p }}{{ $p = $context.Site.GetPage (printf "/%s" (lower (strings.TrimSuffix ".md" $path))) }}{{ end -}} + {{- if $p -}} {{- $p.Content -}} {{- else -}} - {{/* Fallback to readFile for non-page files */}} - {{- if fileExists $path -}} - {{- $content := readFile $path -}} + {{/* Fallback to readFile - check multiple path variations */}} + {{- $found := false -}} + {{- $content := "" -}} + {{- $pathsToTry := slice $path (printf "content/%s" $path) (printf "/%s" $path) -}} + + {{- range $pathsToTry -}} + {{- if and (not $found) (fileExists .) -}} + {{- $content = readFile . -}} + {{- $found = true -}} + {{- end -}} + {{- end -}} + + {{- if $found -}} {{/* Strip frontmatter if it exists */}} {{- if (findRE "^---" $content) -}} {{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}}