summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-05-15 11:48:34 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-05-15 12:39:33 +0200
commit1aacfced390604eee7fc48eb13b9b45f8399a557 (patch)
treeeb4ba25b23768138ddb4f950c6116ba08980f789
parent32c967551be308fbd14e5f0dfba0ff50a60e7f5e (diff)
Fix paths with dots issue with content adapters
Fixes #12493
-rw-r--r--hugolib/page__new.go3
-rw-r--r--hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go17
-rw-r--r--resources/page/pagemeta/page_frontmatter.go20
3 files changed, 31 insertions, 9 deletions
diff --git a/hugolib/page__new.go b/hugolib/page__new.go
index 04c68ba6a..b7d9b10f2 100644
--- a/hugolib/page__new.go
+++ b/hugolib/page__new.go
@@ -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
diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
index 60930321a..f09fa3dc1 100644
--- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
+++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
@@ -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)
+}
diff --git a/resources/page/pagemeta/page_frontmatter.go b/resources/page/pagemeta/page_frontmatter.go
index 87f38674c..d5ed1e401 100644
--- a/resources/page/pagemeta/page_frontmatter.go
+++ b/resources/page/pagemeta/page_frontmatter.go
@@ -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 {