| 1 |
// Copyright 2021 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 page_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gohugoio/hugo/hugolib" |
| 20 |
) |
| 21 |
|
| 22 |
func TestGroupByLocalizedDate(t *testing.T) { |
| 23 |
files := ` |
| 24 |
-- hugo.toml -- |
| 25 |
defaultContentLanguage = 'en' |
| 26 |
defaultContentLanguageInSubdir = true |
| 27 |
[languages] |
| 28 |
[languages.en] |
| 29 |
title = 'My blog' |
| 30 |
weight = 1 |
| 31 |
[languages.fr] |
| 32 |
title = 'Mon blogue' |
| 33 |
weight = 2 |
| 34 |
[languages.nn] |
| 35 |
title = 'Bloggen min' |
| 36 |
weight = 3 |
| 37 |
-- content/p1.md -- |
| 38 |
--- |
| 39 |
title: "Post 1" |
| 40 |
date: "2020-01-01" |
| 41 |
--- |
| 42 |
-- content/p2.md -- |
| 43 |
--- |
| 44 |
title: "Post 2" |
| 45 |
date: "2020-02-01" |
| 46 |
--- |
| 47 |
-- content/p1.fr.md -- |
| 48 |
--- |
| 49 |
title: "Post 1" |
| 50 |
date: "2020-01-01" |
| 51 |
--- |
| 52 |
-- content/p2.fr.md -- |
| 53 |
--- |
| 54 |
title: "Post 2" |
| 55 |
date: "2020-02-01" |
| 56 |
--- |
| 57 |
-- layouts/home.html -- |
| 58 |
{{ range $k, $v := site.RegularPages.GroupByDate "January, 2006" }}{{ $k }}|{{ $v.Key }}|{{ $v.Pages }}{{ end }} |
| 59 |
|
| 60 |
` |
| 61 |
|
| 62 |
b := hugolib.Test(t, files, hugolib.TestOptOsFs()) |
| 63 |
|
| 64 |
b.AssertFileContent("public/en/index.html", "0|February, 2020|Pages(1)1|January, 2020|Pages(1)") |
| 65 |
b.AssertFileContent("public/fr/index.html", "0|février, 2020|Pages(1)1|janvier, 2020|Pages(1)") |
| 66 |
} |
| 67 |
|
| 68 |
func TestPagesSortCollation(t *testing.T) { |
| 69 |
files := ` |
| 70 |
-- hugo.toml -- |
| 71 |
defaultContentLanguage = 'en' |
| 72 |
defaultContentLanguageInSubdir = true |
| 73 |
[languages] |
| 74 |
[languages.en] |
| 75 |
title = 'My blog' |
| 76 |
weight = 1 |
| 77 |
[languages.fr] |
| 78 |
title = 'Mon blogue' |
| 79 |
weight = 2 |
| 80 |
[languages.nn] |
| 81 |
title = 'Bloggen min' |
| 82 |
weight = 3 |
| 83 |
-- content/p1.md -- |
| 84 |
--- |
| 85 |
title: "zulu" |
| 86 |
date: "2020-01-01" |
| 87 |
param1: "xylophone" |
| 88 |
tags: ["xylophone", "éclair", "zulu", "emma"] |
| 89 |
--- |
| 90 |
-- content/p2.md -- |
| 91 |
--- |
| 92 |
title: "émotion" |
| 93 |
date: "2020-01-01" |
| 94 |
param1: "violin" |
| 95 |
--- |
| 96 |
-- content/p3.md -- |
| 97 |
--- |
| 98 |
title: "alpha" |
| 99 |
date: "2020-01-01" |
| 100 |
param1: "éclair" |
| 101 |
--- |
| 102 |
-- layouts/home.html -- |
| 103 |
ByTitle: {{ range site.RegularPages.ByTitle }}{{ .Title }}|{{ end }} |
| 104 |
ByLinkTitle: {{ range site.RegularPages.ByLinkTitle }}{{ .Title }}|{{ end }} |
| 105 |
ByParam: {{ range site.RegularPages.ByParam "param1" }}{{ .Params.param1 }}|{{ end }} |
| 106 |
Tags Alphabetical: {{ range site.Taxonomies.tags.Alphabetical }}{{ .Term }}|{{ end }} |
| 107 |
GroupBy: {{ range site.RegularPages.GroupBy "Title" }}{{ .Key }}|{{ end }} |
| 108 |
{{ with (site.GetPage "p1").Params.tags }} |
| 109 |
Sort: {{ sort . }} |
| 110 |
ByWeight: {{ range site.RegularPages.ByWeight }}{{ .Title }}|{{ end }} |
| 111 |
{{ end }} |
| 112 |
|
| 113 |
` |
| 114 |
|
| 115 |
b := hugolib.Test(t, files, hugolib.TestOptOsFs()) |
| 116 |
|
| 117 |
b.AssertFileContent("public/en/index.html", ` |
| 118 |
ByTitle: alpha|émotion|zulu| |
| 119 |
ByLinkTitle: alpha|émotion|zulu| |
| 120 |
ByParam: éclair|violin|xylophone |
| 121 |
Tags Alphabetical: éclair|emma|xylophone|zulu| |
| 122 |
GroupBy: alpha|émotion|zulu| |
| 123 |
Sort: [éclair emma xylophone zulu] |
| 124 |
ByWeight: alpha|émotion|zulu| |
| 125 |
`) |
| 126 |
} |
| 127 |
|
| 128 |
// See #10377 |
| 129 |
func TestPermalinkExpansionSectionsRepeated(t *testing.T) { |
| 130 |
t.Parallel() |
| 131 |
|
| 132 |
files := ` |
| 133 |
-- hugo.toml -- |
| 134 |
disableKinds = ["home", "taxonomy", "taxonomyTerm", "sitemap"] |
| 135 |
[outputs] |
| 136 |
home = ["HTML"] |
| 137 |
page = ["HTML"] |
| 138 |
section = ["HTML"] |
| 139 |
[outputFormats] |
| 140 |
[permalinks] |
| 141 |
posts = '/:sections[1]/:sections[last]/:slug' |
| 142 |
-- content/posts/_index.md -- |
| 143 |
-- content/posts/a/_index.md -- |
| 144 |
-- content/posts/a/b/_index.md -- |
| 145 |
-- content/posts/a/b/c/_index.md -- |
| 146 |
-- content/posts/a/b/c/d.md -- |
| 147 |
--- |
| 148 |
title: "D" |
| 149 |
slug: "d" |
| 150 |
--- |
| 151 |
D |
| 152 |
-- layouts/single.html -- |
| 153 |
RelPermalink: {{ .RelPermalink }} |
| 154 |
|
| 155 |
` |
| 156 |
|
| 157 |
b := hugolib.Test(t, files) |
| 158 |
|
| 159 |
b.AssertFileContent("public/a/c/d/index.html", "RelPermalink: /a/c/d/") |
| 160 |
} |