mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
Add path, kind and lang to content front matter
Note that none of these can be set via cascade (you will get an error) Fixes #11544
This commit is contained in:
@@ -13,7 +13,11 @@
|
||||
|
||||
package hugolib
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
)
|
||||
|
||||
func TestFrontMatterParamsInItsOwnSection(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -52,3 +56,106 @@ Summary: {{ .Summary }}|
|
||||
"Summary: frontmatter.summary|",
|
||||
)
|
||||
}
|
||||
|
||||
func TestFrontMatterParamsKindPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org/"
|
||||
disableKinds = ["taxonomy", "term"]
|
||||
|
||||
-- content/p1.md --
|
||||
---
|
||||
title: "P1"
|
||||
date: 2019-08-07
|
||||
path: "/a/b/c"
|
||||
slug: "s1"
|
||||
---
|
||||
-- content/mysection.md --
|
||||
---
|
||||
title: "My Section"
|
||||
kind: "section"
|
||||
date: 2022-08-07
|
||||
path: "/a/b"
|
||||
---
|
||||
-- layouts/index.html --
|
||||
RegularPages: {{ range site.RegularPages }}{{ .Path }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Date.Format "2006-02-01" }}| Slug: {{ .Params.slug }}|{{ end }}$
|
||||
Sections: {{ range site.Sections }}{{ .Path }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Date.Format "2006-02-01" }}| Slug: {{ .Params.slug }}|{{ end }}$
|
||||
{{ $ab := site.GetPage "a/b" }}
|
||||
a/b pages: {{ range $ab.RegularPages }}{{ .Path }}|{{ .RelPermalink }}|{{ end }}$
|
||||
`
|
||||
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"RegularPages: /a/b/c|/a/b/s1/|P1|2019-07-08| Slug: s1|$",
|
||||
"Sections: /a|/a/|As",
|
||||
"a/b pages: /a/b/c|/a/b/s1/|$",
|
||||
)
|
||||
}
|
||||
|
||||
func TestFrontMatterParamsLang(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org/"
|
||||
disableKinds = ["taxonomy", "term"]
|
||||
defaultContentLanguage = "en"
|
||||
defaultContentLanguageInSubdir = true
|
||||
[languages]
|
||||
[languages.en]
|
||||
weight = 1
|
||||
[languages.nn]
|
||||
weight = 2
|
||||
-- content/p1.md --
|
||||
---
|
||||
title: "P1 nn"
|
||||
lang: "nn"
|
||||
---
|
||||
-- content/p2.md --
|
||||
---
|
||||
title: "P2"
|
||||
---
|
||||
-- layouts/index.html --
|
||||
RegularPages: {{ range site.RegularPages }}{{ .Path }}|{{ .RelPermalink }}|{{ .Title }}|{{ end }}$
|
||||
|
||||
`
|
||||
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/en/index.html",
|
||||
"RegularPages: /p2|/en/p2/|P2|$",
|
||||
)
|
||||
b.AssertFileContent("public/nn/index.html",
|
||||
"RegularPages: /p1|/nn/p1/|P1 nn|$",
|
||||
)
|
||||
}
|
||||
|
||||
func TestFrontMatterParamsLangNoCascade(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org/"
|
||||
disableKinds = ["taxonomy", "term"]
|
||||
defaultContentLanguage = "en"
|
||||
defaultContentLanguageInSubdir = true
|
||||
[languages]
|
||||
[languages.en]
|
||||
weight = 1
|
||||
[languages.nn]
|
||||
weight = 2
|
||||
-- content/_index.md --
|
||||
+++
|
||||
[[cascade]]
|
||||
background = 'yosemite.jpg'
|
||||
lang = 'nn'
|
||||
+++
|
||||
|
||||
`
|
||||
|
||||
b, err := TestE(t, files)
|
||||
b.Assert(err, qt.IsNotNil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user