| 1 |
// Copyright 2024 The Hugo Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package hugolib |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
qt "github.com/frankban/quicktest" |
| 20 |
) |
| 21 |
|
| 22 |
func TestFrontMatterParamsInItsOwnSection(t *testing.T) { |
| 23 |
t.Parallel() |
| 24 |
|
| 25 |
files := ` |
| 26 |
-- hugo.toml -- |
| 27 |
baseURL = "https://example.org/" |
| 28 |
-- content/_index.md -- |
| 29 |
+++ |
| 30 |
title = "Home" |
| 31 |
[[cascade]] |
| 32 |
background = 'yosemite.jpg' |
| 33 |
[cascade.params] |
| 34 |
a = "home-a" |
| 35 |
b = "home-b" |
| 36 |
[cascade.target] |
| 37 |
kind = 'page' |
| 38 |
+++ |
| 39 |
-- content/p1.md -- |
| 40 |
--- |
| 41 |
title: "P1" |
| 42 |
summary: "frontmatter.summary" |
| 43 |
params: |
| 44 |
a: "p1-a" |
| 45 |
summary: "params.summary" |
| 46 |
--- |
| 47 |
-- layouts/single.html -- |
| 48 |
Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$ |
| 49 |
Summary: {{ .Summary }}| |
| 50 |
` |
| 51 |
|
| 52 |
b := Test(t, files) |
| 53 |
|
| 54 |
b.AssertFileContent("public/p1/index.html", |
| 55 |
"Params: a: p1-a|b: home-b|background: yosemite.jpg|draft: false|iscjklanguage: false|summary: params.summary|title: P1|$", |
| 56 |
"Summary: frontmatter.summary|", |
| 57 |
) |
| 58 |
} |
| 59 |
|
| 60 |
// Issue 11970. |
| 61 |
func TestFrontMatterBuildIsHugoKeyword(t *testing.T) { |
| 62 |
t.Parallel() |
| 63 |
|
| 64 |
files := ` |
| 65 |
-- hugo.toml -- |
| 66 |
baseURL = "https://example.org/" |
| 67 |
-- content/p1.md -- |
| 68 |
--- |
| 69 |
title: "P1" |
| 70 |
build: "foo" |
| 71 |
--- |
| 72 |
-- layouts/single.html -- |
| 73 |
Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$ |
| 74 |
` |
| 75 |
b, err := TestE(t, files) |
| 76 |
|
| 77 |
b.Assert(err, qt.IsNotNil) |
| 78 |
b.Assert(err.Error(), qt.Contains, "We renamed the _build keyword") |
| 79 |
} |