| 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 page_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gohugoio/hugo/hugolib" |
| 20 |
) |
| 21 |
|
| 22 |
func TestTaxonomiesGetAndCount(t *testing.T) { |
| 23 |
t.Parallel() |
| 24 |
|
| 25 |
files := ` |
| 26 |
-- hugo.toml -- |
| 27 |
disableKinds = ['rss','sitemap'] |
| 28 |
[taxonomies] |
| 29 |
author = 'authors' |
| 30 |
-- layouts/home.html -- |
| 31 |
John Smith count: {{ site.Taxonomies.authors.Count "John Smith" }} |
| 32 |
Robert Jones count: {{ (site.Taxonomies.authors.Get "Robert Jones").Pages.Len }} |
| 33 |
-- layouts/single.html -- |
| 34 |
{{ .Title }}| |
| 35 |
-- layouts/list.html -- |
| 36 |
{{ .Title }}| |
| 37 |
-- content/p1.md -- |
| 38 |
--- |
| 39 |
title: p1 |
| 40 |
authors: [John Smith,Robert Jones] |
| 41 |
--- |
| 42 |
-- content/p2.md -- |
| 43 |
--- |
| 44 |
title: p2 |
| 45 |
authors: [John Smith] |
| 46 |
--- |
| 47 |
` |
| 48 |
|
| 49 |
b := hugolib.Test(t, files) |
| 50 |
|
| 51 |
b.AssertFileContent("public/index.html", |
| 52 |
"John Smith count: 2", |
| 53 |
"Robert Jones count: 1", |
| 54 |
) |
| 55 |
} |
| 56 |
|
| 57 |
func TestTaxonomiesPage(t *testing.T) { |
| 58 |
t.Parallel() |
| 59 |
|
| 60 |
files := ` |
| 61 |
-- hugo.toml -- |
| 62 |
disableKinds = ['rss','section','sitemap'] |
| 63 |
[taxonomies] |
| 64 |
tag = 'tags' |
| 65 |
category = 'categories' |
| 66 |
-- content/p1.md -- |
| 67 |
--- |
| 68 |
title: p1 |
| 69 |
tags: [tag-a] |
| 70 |
--- |
| 71 |
-- layouts/list.html -- |
| 72 |
{{- with site.Taxonomies.tags.Page }}{{ .RelPermalink }}{{ end }}| |
| 73 |
{{- with site.Taxonomies.categories.Page }}{{ .RelPermalink }}{{ end }}| |
| 74 |
-- layouts/single.html -- |
| 75 |
{{ .Title }} |
| 76 |
` |
| 77 |
|
| 78 |
b := hugolib.Test(t, files) |
| 79 |
|
| 80 |
b.AssertFileContent("public/index.html", "/tags/||") |
| 81 |
} |