Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc content adapter fixes #12498

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hugolib/page__new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,44 @@ 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)
}

func TestPagesFromGoParamsIssue12497(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
disableKinds = ['home','section','rss','sitemap','taxonomy','term']
-- content/_content.gotmpl --
{{ .AddPage (dict "path" "p1" "title" "p1" "params" (dict "paraM1" "param1v" )) }}
{{ .AddResource (dict "path" "p1/data1.yaml" "content" (dict "value" "data1" ) "params" (dict "paraM1" "param1v" )) }}
-- layouts/_default/single.html --
{{ .Title }}|{{ .Params.paraM1 }}
{{ range .Resources }}
{{ .Name }}|{{ .Params.paraM1 }}
{{ end }}
`

b := hugolib.Test(t, files)

b.AssertFileContent("public/p1/index.html",
"p1|param1v",
"data1.yaml|param1v",
)
}
21 changes: 15 additions & 6 deletions resources/page/pagemeta/page_frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,10 @@ 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.Params == nil {
p.Params = make(maps.Params)
}
maps.PrepareParams(p.Params)

if p.Content.Markup == "" && p.Content.MediaType == "" {
if ext == "" {
Expand Down Expand Up @@ -190,6 +187,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 {
Expand Down
Loading