{{/* 
  Partial: include.html
  Simple include using content/configs mount
*/}}
{{- $path := .path -}}
{{- $context := .context -}}

{{- $originalPath := $path -}}
{{- $found := false -}}
{{- $content := "" -}}
{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}}

{{/* 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 /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 -}}

{{- if $found -}}
  {{- if $isMarkdown -}}
    {{/* Strip frontmatter if it exists */}}
    {{- if (findRE "^---" $content) -}}
      {{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}}
    {{- end -}}
    {{- $context.RenderString $content -}}
  {{- else -}}
    {{/* Output raw content for non-markdown files */}}
    {{- $content | safeHTML -}}
  {{- end -}}
{{- else -}}
  {{- warnf "Include file not found: %s" $originalPath -}}
  <p class="text-red-500 font-bold">[Include Error: File "{{ $originalPath }}" not found]</p>
{{- end -}}
