fixed the include partial and its configuration. The primary issues were the lack of frontmatter stripping and restricted file system access for files outside the Hugo project
root.
Changes Made:
1. Improved include.html Partial:
* Page Support: Now uses .Site.GetPage first, allowing files to be included via Hugo's virtual filesystem (mounts).
* Frontmatter Stripping: Added a regex-based stripper to ensure that if a raw file is read via readFile, its YAML/TOML frontmatter isn't rendered as text/horizontal rules.
* Shortcode Processing: Confirmed that RenderString correctly processes shortcodes within included content.
2. Updated Hugo Configuration:
* Added [[module.mounts]] to /srv/dev/hugo/wiki/config/_default/hugo.toml to expose your private documentation directory (/srv/docs/private) to Hugo as content/private.
This commit is contained in:
@@ -42,3 +42,10 @@ enableGitInfo = true
|
|||||||
endLevel = 3
|
endLevel = 3
|
||||||
ordered = false
|
ordered = false
|
||||||
startLevel = 2
|
startLevel = 2
|
||||||
|
[module]
|
||||||
|
[[module.mounts]]
|
||||||
|
source = "content"
|
||||||
|
target = "content"
|
||||||
|
[[module.mounts]]
|
||||||
|
source = "/srv/docs/private"
|
||||||
|
target = "content/private"
|
||||||
|
|||||||
@@ -2,16 +2,27 @@
|
|||||||
Partial: include.html
|
Partial: include.html
|
||||||
Handles including external Markdown files and rendering them.
|
Handles including external Markdown files and rendering them.
|
||||||
Parameters:
|
Parameters:
|
||||||
- context: The Page context (required for RenderString)
|
- context: The Page context (required for RenderString/GetPage)
|
||||||
- path: Path to the file, relative to the project root
|
- path: Path to the file, relative to the project root or content root
|
||||||
*/}}
|
*/}}
|
||||||
{{- $path := .path -}}
|
{{- $path := .path -}}
|
||||||
{{- $context := .context -}}
|
{{- $context := .context -}}
|
||||||
|
|
||||||
|
{{/* Try to get as a Page first (supports mounts and already handles frontmatter) */}}
|
||||||
|
{{- $p := $context.Site.GetPage $path -}}
|
||||||
|
{{- if $p -}}
|
||||||
|
{{- $p.Content -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{/* Fallback to readFile for non-page files */}}
|
||||||
{{- if fileExists $path -}}
|
{{- if fileExists $path -}}
|
||||||
{{- $content := readFile $path -}}
|
{{- $content := readFile $path -}}
|
||||||
|
{{/* Strip frontmatter if it exists */}}
|
||||||
|
{{- if (findRE "^---" $content) -}}
|
||||||
|
{{- $content = replaceRE "^(?s)---.*?---[\\r\\n]*" "" $content -}}
|
||||||
|
{{- end -}}
|
||||||
{{- $context.RenderString $content -}}
|
{{- $context.RenderString $content -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- warnf "Include file not found: %s" $path -}}
|
{{- warnf "Include file not found: %s" $path -}}
|
||||||
<p class="text-red-500 font-bold">[Include Error: File "{{ $path }}" not found]</p>
|
<p class="text-red-500 font-bold">[Include Error: File "{{ $path }}" not found]</p>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user