From 80595bbe3e7901ecd6200e59d43af142c3c85b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 30 Jan 2024 10:42:24 +0100 Subject: [PATCH] Fix recent regression .Resources.Get for resources with spaces in filename Fixes #11944 --- hugolib/content_map_page.go | 2 +- hugolib/content_map_test.go | 19 +++++++++++++++++++ resources/page/pagemeta/page_frontmatter.go | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 9fee74003..9accd190e 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -1548,7 +1548,7 @@ func (sa *sitePagesAssembler) assembleResources() error { return false, nil } - relPathOriginal := rs.path.PathRel(ps.m.pathInfo) + relPathOriginal := rs.path.Unmormalized().PathRel(ps.m.pathInfo.Unmormalized()) relPath := rs.path.BaseRel(ps.m.pathInfo) var targetBasePaths []string diff --git a/hugolib/content_map_test.go b/hugolib/content_map_test.go index a41b2aae9..7843ad285 100644 --- a/hugolib/content_map_test.go +++ b/hugolib/content_map_test.go @@ -280,3 +280,22 @@ P1: {{ $p1.Title }}|{{ $p1.Params.foo }}|{{ $p1.File.Filename }}| filepath.FromSlash("P1: P1 md|md|/content/p1.md|"), ) } + +// Issue #11944 +func TestBundleResourcesGetWithSpacesInFilename(t *testing.T) { + files := ` +-- hugo.toml -- +baseURL = "https://example.com" +disableKinds = ["taxonomy", "term"] +-- content/bundle/index.md -- +-- content/bundle/data with Spaces.txt -- +Data. +-- layouts/index.html -- +{{ $bundle := site.GetPage "bundle" }} +{{ $r := $bundle.Resources.Get "data with Spaces.txt" }} +R: {{ with $r }}{{ .Content }}{{ end }}| +` + b := Test(t, files) + + b.AssertFileContent("public/index.html", "R: Data.") +} diff --git a/resources/page/pagemeta/page_frontmatter.go b/resources/page/pagemeta/page_frontmatter.go index 17859d846..8abd3807f 100644 --- a/resources/page/pagemeta/page_frontmatter.go +++ b/resources/page/pagemeta/page_frontmatter.go @@ -57,7 +57,7 @@ func (d Dates) IsAllDatesZero() bool { // Note that all the top level fields are reserved Hugo keywords. // Any custom configuration needs to be set in the Params map. type PageConfig struct { - Dates // Dates holds the fource core dates for this page. + Dates // Dates holds the four core dates for this page. Title string // The title of the page. LinkTitle string // The link title of the page. Type string // The content type of the page. @@ -66,6 +66,7 @@ type PageConfig struct { Weight int // The weight of the page, used in sorting if set to a non-zero value. Kind string // The kind of page, e.g. "page", "section", "home" etc. This is usually derived from the content path. Path string // The canonical path to the page, e.g. /sect/mypage. Note: Leading slash, no trailing slash, no extensions or language identifiers. + URL string // The URL to the rendered page, e.g. /sect/mypage.html. Lang string // The language code for this page. This is usually derived from the module mount or filename. Slug string // The slug for this page. Description string // The description for this page.