]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix paths with dots issue with content adapters
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 15 May 2024 09:48:34 +0000 (11:48 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 15 May 2024 10:39:33 +0000 (12:39 +0200)
Fixes #12493

hugolib/page__new.go
hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
resources/page/pagemeta/page_frontmatter.go

index 04c68ba6a00f6c224e40c9f8fd34e8d272efb05e..b7d9b10f279964ae842b70305169e209641bc5a7 100644 (file)
@@ -62,7 +62,8 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
 
        if pcfg.Path != "" {
                s := m.pageConfig.Path
-               if !paths.HasExt(s) {
+               // Paths from content adapters should never have any extension.
+               if pcfg.IsFromContentAdapter || !paths.HasExt(s) {
                        var (
                                isBranch    bool
                                isBranchSet bool
index 60930321a567bb6a2ea5727351a147b9ac1ec340..f09fa3dc1022a2bed2cbbfe9419da5ff5a485791 100644 (file)
@@ -477,3 +477,20 @@ baseURL = "https://example.com"
        b.AssertFileExists("public/docs/p1/index.html", true)
        b.AssertFileExists("public/docs/p2/index.html", false)
 }
+
+func TestPagesFromGoPathsWithDotsIssue12493(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['home','section','rss','sitemap','taxonomy','term']
+-- content/_content.gotmpl --
+{{ .AddPage (dict "path" "s-1.2.3/p-4.5.6" "title" "p-4.5.6") }}
+-- layouts/_default/single.html --
+{{ .Title }}
+`
+
+       b := hugolib.Test(t, files)
+
+       b.AssertFileExists("public/s-1.2.3/p-4.5.6/index.html", true)
+}
index 87f38674c2487c1ef0eb0dc64a0351bdf2342640..d5ed1e401b3400803b7e3f1d968fe0dcf60c48ec 100644 (file)
@@ -151,14 +151,6 @@ func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, lo
                p.Path = path.Join(basePath, p.Path)
        }
 
-       if pagesFromData {
-               // Note that NormalizePathStringBasic will make sure that we don't preserve the unnormalized path.
-               // We do that when we create pages from the file system; mostly for backward compatibility,
-               // but also because people tend to use use the filename to name their resources (with spaces and all),
-               // and this isn't relevant when creating resources from an API where it's easy to add textual meta data.
-               p.Path = paths.NormalizePathStringBasic(p.Path)
-       }
-
        if p.Content.Markup == "" && p.Content.MediaType == "" {
                if ext == "" {
                        ext = "md"
@@ -190,6 +182,18 @@ func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, lo
                p.Content.Markup = p.ContentMediaType.SubType
        }
 
+       if pagesFromData {
+               if p.Kind == "" {
+                       p.Kind = kinds.KindPage
+               }
+
+               // Note that NormalizePathStringBasic will make sure that we don't preserve the unnormalized path.
+               // We do that when we create pages from the file system; mostly for backward compatibility,
+               // but also because people tend to use use the filename to name their resources (with spaces and all),
+               // and this isn't relevant when creating resources from an API where it's easy to add textual meta data.
+               p.Path = paths.NormalizePathStringBasic(p.Path)
+       }
+
        if p.Cascade != nil {
                cascade, err := page.DecodeCascade(logger, p.Cascade)
                if err != nil {