From 9df0017182a898ded8e9057006fe6247d65d4d92 Mon Sep 17 00:00:00 2001 From: wompmacho Date: Sun, 29 Mar 2026 00:15:32 +0000 Subject: [PATCH] updates to try and fix partial includes issue 1. Restored resume.md: Left exactly as it was. 2. Configured hugo.toml Mounts: I mounted /srv/configs into the virtual assets namespace. This securely gives Hugo access to those files as raw static resources. 3. Updated include Partial: I rewrote the shortcode partial (layouts/partials/include.html) to: * Intercept absolute paths starting with /srv/configs/, map them to configs/..., and retrieve their raw text content using resources.Get. * Intercept paths starting with /srv/docs/private/, look them up as a Page, and use .RawContent instead of .Content (which prevents Hugo from wrapping your Markdown in HTML

tags when injecting it into your code blocks). * Strip any YAML frontmatter from the raw content using a regex replaceRE block. --- config/_default/hugo.toml | 22 +++++++------ config/_default/security.toml | 4 --- layouts/partials/include.html | 62 +++++++++++++++++------------------ 3 files changed, 42 insertions(+), 46 deletions(-) delete mode 100644 config/_default/security.toml diff --git a/config/_default/hugo.toml b/config/_default/hugo.toml index c7ede2b..4674933 100644 --- a/config/_default/hugo.toml +++ b/config/_default/hugo.toml @@ -1,6 +1,4 @@ # -- Site Configuration -- -# Refer to the theme docs for more details about each of these parameters. -# https://nunocoracao.github.io/blowfish/docs/getting-started/ theme = ["hugo-admonitions", "blowfish"] baseURL = "https://wiki.wompmacho.com/" @@ -14,8 +12,6 @@ buildDrafts = true buildFuture = true enableEmoji = true -# googleAnalytics = "G-XXXXXXXXX" - [taxonomies] tag = "tags" category = "categories" @@ -23,19 +19,16 @@ enableEmoji = true series = "series" [sitemap] - changefreq = 'daily' - filename = 'sitemap.xml' + changefreq = "daily" + filename = "sitemap.xml" priority = 0.5 [outputs] home = ["HTML", "RSS", "JSON"] [frontmatter] - # Hugo will check for 'lastmod' in the file first, - # then the Git commit date, then the 'date' field. lastmod = ["lastmod", ":git", "date"] -# Required if you want to use the Git commit date automatically enableGitInfo = true [markup.tableOfContents] @@ -52,4 +45,13 @@ enableGitInfo = true target = "content/private" [[module.mounts]] source = "/srv/configs" - target = "content/configs" + target = "assets/configs" + +[security] + [security.funcs] + readFile = [".*"] + "os.Stat" = [".*"] + "os.ReadDir" = [".*"] + [[module.mounts]] + source = "assets" + target = "assets" diff --git a/config/_default/security.toml b/config/_default/security.toml deleted file mode 100644 index 07fa341..0000000 --- a/config/_default/security.toml +++ /dev/null @@ -1,4 +0,0 @@ -[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/layouts/partials/include.html b/layouts/partials/include.html index 0ec0207..f21976a 100644 --- a/layouts/partials/include.html +++ b/layouts/partials/include.html @@ -1,46 +1,44 @@ -{{/* - Partial: include.html - Simple include using content/configs mount -*/}} {{- $path := .path -}} -{{- $context := .context -}} - -{{- $originalPath := $path -}} -{{- $found := false -}} {{- $content := "" -}} -{{- $isMarkdown := strings.HasSuffix (lower $path) ".md" -}} +{{- $found := false -}} -{{/* 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 -}} +{{- /* Handle /srv/configs/ mapping to assets mount (mounted at assets/configs) */ -}} +{{- if strings.HasPrefix $path "/srv/configs/" -}} + {{- $assetPath := strings.TrimPrefix "/srv/" $path -}} + {{- $res := resources.Get $assetPath -}} + {{- if $res -}} + {{- $content = $res.Content -}} + {{- $found = true -}} + {{- end -}} {{- end -}} -{{/* 2. Map /srv/docs/private/ -> content/private/ */}} +{{- /* Handle /srv/docs/private/ mapping to content mount */ -}} {{- if not $found -}} - {{- $mappedPath = replace $path "/srv/docs/private/" "content/private/" -}} - {{- $mappedPath = strings.TrimLeft "/" $mappedPath -}} - {{- if fileExists $mappedPath -}} - {{- $content = readFile $mappedPath -}} + {{- if strings.HasPrefix $path "/srv/docs/private/" -}} + {{- $pagePath := strings.TrimPrefix "/srv/docs/private/" $path -}} + {{- $p := site.GetPage (printf "private/%s" $pagePath) -}} + {{- if $p -}} + {{- $content = $p.RawContent -}} + {{- $found = true -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{- /* Handle relative or other paths by direct Page lookup */ -}} +{{- if not $found -}} + {{- $p := site.GetPage $path -}} + {{- if $p -}} + {{- $content = $p.RawContent -}} {{- $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 -}} + {{- /* Fallback manual frontmatter strip for assets that might have it */ -}} + {{- if findRE "^---" $content -}} + {{- $content = replaceRE "^(?s)---[\\s\\S]*?---[\\r\\n]*" "" $content -}} {{- end -}} + {{- $content | safeHTML -}} {{- else -}} - {{- warnf "Include file not found: %s" $originalPath -}} -

[Include Error: File "{{ $originalPath }}" not found]

+ {{- warnf "WARN Include file not found: %s" $path -}} {{- end -}}