aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/params_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-01-28 17:32:26 +0100
committerBjørn Erik Pedersen <[email protected]>2024-01-28 21:38:40 +0100
commit6dedb4efc7b6a9fbe58a2daf0f77182638840fd9 (patch)
tree498ce0c315623d20c2ab9ed166f3133a9185b689 /hugolib/params_test.go
parent292626e679e5203faf3d42f004c12027da3e4300 (diff)
downloadhugo-6dedb4efc7b6a9fbe58a2daf0f77182638840fd9.tar.gz
hugo-6dedb4efc7b6a9fbe58a2daf0f77182638840fd9.zip
Add the [params] concept to front matter
This is deliberately very simple, but should not break anything. We need to introduce this in baby steps, but this should allow us to introduce this in the documentation. Note that the `params` section's key/values will be added to `.Params` last. This means that you can have different values for "Hugo's summary" and the custom ".Params.summary" if you want to. Updates #11055
Diffstat (limited to 'hugolib/params_test.go')
-rw-r--r--hugolib/params_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/hugolib/params_test.go b/hugolib/params_test.go
new file mode 100644
index 000000000..32b4bd7c3
--- /dev/null
+++ b/hugolib/params_test.go
@@ -0,0 +1,54 @@
+// Copyright 2024 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package hugolib
+
+import "testing"
+
+func TestFrontMatterParamsInItsOwnSection(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+baseURL = "https://example.org/"
+-- content/_index.md --
++++
+title = "Home"
+[[cascade]]
+background = 'yosemite.jpg'
+[cascade.params]
+a = "home-a"
+b = "home-b"
+[cascade._target]
+kind = 'page'
++++
+-- content/p1.md --
+---
+title: "P1"
+summary: "frontmatter.summary"
+params:
+ a: "p1-a"
+ summary: "params.summary"
+---
+-- layouts/_default/single.html --
+Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$
+Summary: {{ .Summary }}|
+`
+
+ b := Test(t, files)
+
+ b.AssertFileContent("public/p1/index.html",
+ "Params: a: p1-a|b: home-b|background: yosemite.jpg|draft: false|iscjklanguage: false|summary: params.summary|title: P1|$",
+ "Summary: frontmatter.summary|",
+ )
+}