]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix resource bundling for overlapping page.md vs page.txt
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 2 Apr 2024 09:53:43 +0000 (11:53 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 2 Apr 2024 12:32:05 +0000 (14:32 +0200)
Fixes #12320

hugolib/content_map_page.go
hugolib/pagebundler_test.go

index 2f0a6408bd4f0bae7d1032dde4fe4125c2175d78..ff0b05ed1ec4e8d35ce1319de50e437cdc86e423 100644 (file)
@@ -489,12 +489,17 @@ func (m *pageMap) forEachResourceInPage(
 
        rw.Handle = func(resourceKey string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
                if isBranch {
-                       ownerKey, _ := m.treePages.LongestPrefixAll(resourceKey)
-                       if ownerKey != keyPage && path.Dir(ownerKey) != path.Dir(resourceKey) {
+                       // A resourceKey always represents a filename with extension.
+                       // A page key points to the logical path of a page, which when sourced from the filesystem
+                       // may represent a directory (bundles) or a single content file (e.g. p1.md).
+                       // So, to avoid any overlapping ambiguity, we start looking from the owning directory.
+                       ownerKey, _ := m.treePages.LongestPrefixAll(path.Dir(resourceKey))
+                       if ownerKey != keyPage {
                                // Stop walking downwards, someone else owns this resource.
                                rw.SkipPrefix(ownerKey + "/")
                                return false, nil
                        }
+
                }
                return handle(resourceKey, n, match)
        }
index a46ef0b56437280a3dd74f43a144f10dd47f6ddf..302201a1f8e077cd308b2683553c38e74fdeadd6 100644 (file)
@@ -919,3 +919,42 @@ GetMatch: {{ with .Resources.GetMatch "f1.*" }}{{ .Name }}: {{ .Content }}|{{ en
 
        b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.en.txt: F1.|")
 }
+
+func TestBundleBranchIssue12320(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['rss','sitemap','taxonomy','term']
+defaultContentLanguage = 'en'
+defaultContentLanguageInSubdir = true
+[languages.en]
+baseURL = "https://en.example.org/"
+contentDir = "content/en"
+[languages.fr]
+baseURL = "https://fr.example.org/"
+contentDir = "content/fr"
+-- content/en/s1/p1.md --
+---
+title: p1
+---
+-- content/en/s1/p1.txt --
+---
+p1.txt
+---
+-- layouts/_default/single.html --
+{{ .Title }}|
+-- layouts/_default/list.html --
+{{ .Title }}|
+`
+
+       b := Test(t, files)
+
+       b.AssertFileExists("public/en/s1/index.html", true)
+       b.AssertFileExists("public/en/s1/p1/index.html", true)
+       b.AssertFileExists("public/en/s1/p1.txt", true)
+
+       b.AssertFileExists("public/fr/s1/index.html", false)
+       b.AssertFileExists("public/fr/s1/p1/index.html", false)
+       b.AssertFileExists("public/fr/s1/p1.txt", false) // failing test
+}