| 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_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"strings" |
| 18 |
"testing" |
| 19 |
|
| 20 |
"github.com/gohugoio/hugo/hugolib" |
| 21 |
) |
| 22 |
|
| 23 |
// Issue 9073 |
| 24 |
func TestPageTranslationsMap(t *testing.T) { |
| 25 |
t.Parallel() |
| 26 |
|
| 27 |
files := ` |
| 28 |
-- hugo.toml -- |
| 29 |
baseURL = 'https://example.org/' |
| 30 |
title = 'Issue-9073' |
| 31 |
defaultContentLanguageInSubdir = true |
| 32 |
|
| 33 |
[taxonomies] |
| 34 |
tag = 'tags' |
| 35 |
|
| 36 |
[languages.en] |
| 37 |
contentDir = 'content/en' |
| 38 |
weight = 1 |
| 39 |
disableKinds = ['RSS','sitemap'] |
| 40 |
|
| 41 |
[languages.de] |
| 42 |
contentDir = 'content/de' |
| 43 |
weight = 2 |
| 44 |
disableKinds = ['home', 'page', 'section', 'taxonomy', 'term','RSS','sitemap'] |
| 45 |
-- content/de/posts/p1.md -- |
| 46 |
--- |
| 47 |
title: P1 |
| 48 |
tags: ['T1'] |
| 49 |
--- |
| 50 |
-- content/en/posts/p1.md -- |
| 51 |
--- |
| 52 |
title: P1 |
| 53 |
tags: ['T1'] |
| 54 |
--- |
| 55 |
-- layouts/single.html -- |
| 56 |
<ul>{{ range .AllTranslations }}<li>{{ .Title }}-{{ .Lang }}</li>{{ end }}</ul> |
| 57 |
-- layouts/list.html -- |
| 58 |
<ul>{{ range .AllTranslations }}<li>{{ .Title }}-{{ .Lang }}</li>{{ end }}</ul> |
| 59 |
` |
| 60 |
|
| 61 |
b := hugolib.Test(t, files) |
| 62 |
|
| 63 |
// Kind home |
| 64 |
b.AssertFileContent("public/en/index.html", |
| 65 |
"<ul><li>Issue-9073-en</li></ul>", |
| 66 |
) |
| 67 |
// Kind section |
| 68 |
b.AssertFileContent("public/en/posts/index.html", |
| 69 |
"<ul><li>Posts-en</li></ul>", |
| 70 |
) |
| 71 |
// Kind page |
| 72 |
b.AssertFileContent("public/en/posts/p1/index.html", |
| 73 |
"<ul><li>P1-en</li></ul>", |
| 74 |
) |
| 75 |
// Kind taxonomy |
| 76 |
b.AssertFileContent("public/en/tags/index.html", |
| 77 |
"<ul><li>Tags-en</li></ul>", |
| 78 |
) |
| 79 |
// Kind term |
| 80 |
b.AssertFileContent("public/en/tags/t1/index.html", |
| 81 |
"<ul><li>T1-en</li></ul>", |
| 82 |
) |
| 83 |
} |
| 84 |
|
| 85 |
// Issue #11538 |
| 86 |
func TestRenderStringBadMarkupOpt(t *testing.T) { |
| 87 |
t.Parallel() |
| 88 |
|
| 89 |
files := ` |
| 90 |
-- layouts/home.html -- |
| 91 |
{{ $opts := dict "markup" "foo" }} |
| 92 |
{{ "something" | .RenderString $opts }} |
| 93 |
` |
| 94 |
|
| 95 |
b, err := hugolib.TestE(t, files) |
| 96 |
_ = b |
| 97 |
|
| 98 |
want := `no content renderer found for markup "foo"` |
| 99 |
if !strings.Contains(err.Error(), want) { |
| 100 |
t.Errorf("error msg must contain %q, error msg actually contains %q", want, err.Error()) |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
// Issue #11547 |
| 105 |
func TestTitleCaseStyleWithAutomaticSectionPages(t *testing.T) { |
| 106 |
t.Parallel() |
| 107 |
|
| 108 |
files := ` |
| 109 |
-- hugo.toml -- |
| 110 |
titleCaseStyle = 'none' |
| 111 |
-- content/books/book-1.md -- |
| 112 |
--- |
| 113 |
title: Book 1 |
| 114 |
tags: [fiction] |
| 115 |
--- |
| 116 |
-- content/films/_index.md -- |
| 117 |
--- |
| 118 |
title: Films |
| 119 |
--- |
| 120 |
-- layouts/home.html -- |
| 121 |
{{ (site.GetPage "/tags").Title }} |
| 122 |
{{ (site.GetPage "/tags/fiction").Title }} |
| 123 |
{{ (site.GetPage "/books").Title }} |
| 124 |
{{ (site.GetPage "/films").Title }} |
| 125 |
` |
| 126 |
|
| 127 |
b := hugolib.Test(t, files) |
| 128 |
b.AssertFileContent("public/index.html", "tags\nfiction\nbooks\nFilms") |
| 129 |
} |