2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2015-12-10 17:19:38 -05:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2014-04-08 23:15:57 -04:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
2017-02-17 12:40:08 -05:00
|
|
|
"fmt"
|
2016-11-07 14:24:37 -05:00
|
|
|
"path/filepath"
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
|
|
|
|
2016-12-26 20:42:43 -05:00
|
|
|
"reflect"
|
2017-03-09 13:19:29 -05:00
|
|
|
"strings"
|
2014-04-08 23:15:57 -04:00
|
|
|
"testing"
|
2016-04-01 14:17:16 -04:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
qt "github.com/frankban/quicktest"
|
2017-02-17 12:40:08 -05:00
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/deps"
|
2014-04-08 23:15:57 -04:00
|
|
|
)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func TestTaxonomiesCountOrder(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2016-04-01 14:17:16 -04:00
|
|
|
taxonomies := make(map[string]string)
|
|
|
|
|
|
|
|
taxonomies["tag"] = "tags"
|
|
|
|
taxonomies["category"] = "categories"
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
cfg, fs := newTestCfg()
|
2016-04-01 14:17:16 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
cfg.Set("taxonomies", taxonomies)
|
2016-11-07 14:24:37 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
const pageContent = `---
|
|
|
|
tags: ['a', 'B', 'c']
|
|
|
|
categories: 'd'
|
|
|
|
---
|
|
|
|
YAML frontmatter with tags and categories taxonomy.`
|
|
|
|
|
|
|
|
writeSource(t, fs, filepath.Join("content", "page.md"), pageContent)
|
2016-11-07 14:24:37 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
2016-04-01 14:17:16 -04:00
|
|
|
|
|
|
|
st := make([]string, 0)
|
2019-09-10 05:26:34 -04:00
|
|
|
for _, t := range s.Taxonomies()["tags"].ByCount() {
|
2019-01-02 06:33:26 -05:00
|
|
|
st = append(st, t.Page().Title()+":"+t.Name)
|
2016-04-01 14:17:16 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
expect := []string{"a:a", "B:b", "c:c"}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(st, expect) {
|
|
|
|
t.Fatalf("ordered taxonomies mismatch, expected\n%v\ngot\n%q", expect, st)
|
2016-04-01 14:17:16 -04:00
|
|
|
}
|
|
|
|
}
|
2017-02-17 12:40:08 -05:00
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
//
|
2017-02-17 12:40:08 -05:00
|
|
|
func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) {
|
2017-03-09 13:19:29 -05:00
|
|
|
for _, uglyURLs := range []bool{false, true} {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
uglyURLs := uglyURLs
|
2019-01-02 06:33:26 -05:00
|
|
|
t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
t.Parallel()
|
2019-01-02 06:33:26 -05:00
|
|
|
doTestTaxonomiesWithAndWithoutContentFile(t, uglyURLs)
|
|
|
|
})
|
2017-02-23 04:03:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func doTestTaxonomiesWithAndWithoutContentFile(t *testing.T, uglyURLs bool) {
|
2017-02-17 12:40:08 -05:00
|
|
|
|
|
|
|
siteConfig := `
|
|
|
|
baseURL = "http://example.com/blog"
|
2017-03-09 13:19:29 -05:00
|
|
|
uglyURLs = %t
|
2017-02-17 12:40:08 -05:00
|
|
|
paginate = 1
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
[Taxonomies]
|
|
|
|
tag = "tags"
|
|
|
|
category = "categories"
|
|
|
|
other = "others"
|
2017-03-01 11:07:38 -05:00
|
|
|
empty = "empties"
|
2017-11-06 22:58:41 -05:00
|
|
|
permalinked = "permalinkeds"
|
|
|
|
[permalinks]
|
|
|
|
permalinkeds = "/perma/:slug/"
|
2017-02-17 12:40:08 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
pageTemplate := `---
|
|
|
|
title: "%s"
|
|
|
|
tags:
|
|
|
|
%s
|
|
|
|
categories:
|
|
|
|
%s
|
|
|
|
others:
|
|
|
|
%s
|
2017-11-06 22:58:41 -05:00
|
|
|
permalinkeds:
|
|
|
|
%s
|
2017-02-17 12:40:08 -05:00
|
|
|
---
|
|
|
|
# Doc
|
|
|
|
`
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
siteConfig = fmt.Sprintf(siteConfig, uglyURLs)
|
2017-02-23 04:03:48 -05:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", siteConfig)
|
2019-04-15 03:38:14 -04:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.WithContent(
|
|
|
|
"p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- Tag1", "- cAt1", "- o1", "- Pl1"),
|
|
|
|
"p2.md", fmt.Sprintf(pageTemplate, "t2/c1", "- tag2", "- cAt1", "- o1", "- Pl1"),
|
|
|
|
"p3.md", fmt.Sprintf(pageTemplate, "t2/c12", "- tag2", "- cat2", "- o1", "- Pl1"),
|
|
|
|
"p4.md", fmt.Sprintf(pageTemplate, "Hello World", "", "", "- \"Hello Hugo world\"", "- Pl1"),
|
|
|
|
"categories/_index.md", newTestPage("Category Terms", "2017-01-01", 10),
|
|
|
|
"tags/Tag1/_index.md", newTestPage("Tag1 List", "2017-01-01", 10),
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5847
|
|
|
|
"/tags/not-used/_index.md", newTestPage("Unused Tag List", "2018-01-01", 10),
|
|
|
|
)
|
2018-12-29 04:35:46 -05:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.Build(BuildCfg{})
|
2017-02-17 12:40:08 -05:00
|
|
|
|
|
|
|
// So what we have now is:
|
|
|
|
// 1. categories with terms content page, but no content page for the only c1 category
|
|
|
|
// 2. tags with no terms content page, but content page for one of 2 tags (tag1)
|
|
|
|
// 3. the "others" taxonomy with no content pages.
|
2017-11-07 17:42:47 -05:00
|
|
|
// 4. the "permalinkeds" taxonomy with permalinks configuration.
|
2017-02-17 12:40:08 -05:00
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
pathFunc := func(s string) string {
|
|
|
|
if uglyURLs {
|
|
|
|
return strings.Replace(s, "/index.html", ".html", 1)
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2017-02-17 12:40:08 -05:00
|
|
|
// 1.
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent(pathFunc("public/categories/cat1/index.html"), "List", "cAt1")
|
|
|
|
b.AssertFileContent(pathFunc("public/categories/index.html"), "Taxonomy Term Page", "Category Terms")
|
2017-02-17 12:40:08 -05:00
|
|
|
|
|
|
|
// 2.
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent(pathFunc("public/tags/tag2/index.html"), "List", "tag2")
|
|
|
|
b.AssertFileContent(pathFunc("public/tags/tag1/index.html"), "List", "Tag1")
|
|
|
|
b.AssertFileContent(pathFunc("public/tags/index.html"), "Taxonomy Term Page", "Tags")
|
2017-02-17 12:40:08 -05:00
|
|
|
|
|
|
|
// 3.
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent(pathFunc("public/others/o1/index.html"), "List", "o1")
|
|
|
|
b.AssertFileContent(pathFunc("public/others/index.html"), "Taxonomy Term Page", "Others")
|
2017-02-17 12:40:08 -05:00
|
|
|
|
2017-11-07 17:42:47 -05:00
|
|
|
// 4.
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent(pathFunc("public/perma/pl1/index.html"), "List", "Pl1")
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2017-11-07 17:42:47 -05:00
|
|
|
// This looks kind of funky, but the taxonomy terms do not have a permalinks definition,
|
|
|
|
// for good reasons.
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent(pathFunc("public/permalinkeds/index.html"), "Taxonomy Term Page", "Permalinkeds")
|
2017-11-07 17:42:47 -05:00
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
s := b.H.Sites[0]
|
2017-02-22 15:13:21 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Make sure that each page.KindTaxonomyTerm page has an appropriate number
|
|
|
|
// of page.KindTaxonomy pages in its Pages slice.
|
2017-03-05 15:24:14 -05:00
|
|
|
taxonomyTermPageCounts := map[string]int{
|
2019-04-15 03:38:14 -04:00
|
|
|
"tags": 3,
|
2018-12-29 04:35:46 -05:00
|
|
|
"categories": 2,
|
2017-11-06 22:58:41 -05:00
|
|
|
"others": 2,
|
|
|
|
"empties": 0,
|
|
|
|
"permalinkeds": 1,
|
2017-03-05 15:24:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for taxonomy, count := range taxonomyTermPageCounts {
|
2019-09-10 05:26:34 -04:00
|
|
|
msg := qt.Commentf(taxonomy)
|
2019-01-02 06:33:26 -05:00
|
|
|
term := s.getPage(page.KindTaxonomyTerm, taxonomy)
|
2019-09-10 05:26:34 -04:00
|
|
|
b.Assert(term, qt.Not(qt.IsNil), msg)
|
|
|
|
b.Assert(len(term.Pages()), qt.Equals, count, msg)
|
2017-03-05 15:24:14 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, p := range term.Pages() {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(p.Kind(), qt.Equals, page.KindTaxonomy)
|
2017-03-05 15:24:14 -05:00
|
|
|
}
|
|
|
|
}
|
2017-03-01 06:30:41 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
cat1 := s.getPage(page.KindTaxonomy, "categories", "cat1")
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(cat1, qt.Not(qt.IsNil))
|
2018-12-29 04:35:46 -05:00
|
|
|
if uglyURLs {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1.html")
|
2018-12-29 04:35:46 -05:00
|
|
|
} else {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1/")
|
2018-12-29 04:35:46 -05:00
|
|
|
}
|
2017-03-09 13:19:29 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
pl1 := s.getPage(page.KindTaxonomy, "permalinkeds", "pl1")
|
|
|
|
permalinkeds := s.getPage(page.KindTaxonomyTerm, "permalinkeds")
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(pl1, qt.Not(qt.IsNil))
|
|
|
|
b.Assert(permalinkeds, qt.Not(qt.IsNil))
|
2018-12-29 04:35:46 -05:00
|
|
|
if uglyURLs {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(pl1.RelPermalink(), qt.Equals, "/blog/perma/pl1.html")
|
|
|
|
b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds.html")
|
2018-12-29 04:35:46 -05:00
|
|
|
} else {
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(pl1.RelPermalink(), qt.Equals, "/blog/perma/pl1/")
|
|
|
|
b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds/")
|
2018-12-29 04:35:46 -05:00
|
|
|
}
|
2018-09-21 15:03:17 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
helloWorld := s.getPage(page.KindTaxonomy, "others", "hello-hugo-world")
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(helloWorld, qt.Not(qt.IsNil))
|
|
|
|
b.Assert(helloWorld.Title(), qt.Equals, "Hello Hugo world")
|
2017-02-23 04:03:48 -05:00
|
|
|
|
2017-03-01 11:07:38 -05:00
|
|
|
// Issue #2977
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
b.AssertFileContent(pathFunc("public/empties/index.html"), "Taxonomy Term Page", "Empties")
|
2017-03-01 11:07:38 -05:00
|
|
|
|
2017-02-17 12:40:08 -05:00
|
|
|
}
|
2018-12-29 04:14:37 -05:00
|
|
|
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5513
|
2018-12-29 04:35:46 -05:00
|
|
|
// https://github.com/gohugoio/hugo/issues/5571
|
|
|
|
func TestTaxonomiesPathSeparation(t *testing.T) {
|
2018-12-29 04:14:37 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
config := `
|
|
|
|
baseURL = "https://example.com"
|
|
|
|
[taxonomies]
|
|
|
|
"news/tag" = "news/tags"
|
|
|
|
"news/category" = "news/categories"
|
2018-12-29 04:35:46 -05:00
|
|
|
"t1/t2/t3" = "t1/t2/t3s"
|
|
|
|
"s1/s2/s3" = "s1/s2/s3s"
|
2018-12-29 04:14:37 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
pageContent := `
|
|
|
|
+++
|
|
|
|
title = "foo"
|
2018-12-29 04:35:46 -05:00
|
|
|
"news/categories" = ["a", "b", "c", "d/e", "f/g/h"]
|
|
|
|
"t1/t2/t3s" = ["t4/t5", "t4/t5/t6"]
|
2018-12-29 04:14:37 -05:00
|
|
|
+++
|
|
|
|
Content.
|
|
|
|
`
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithConfigFile("toml", config)
|
|
|
|
b.WithContent("page.md", pageContent)
|
|
|
|
b.WithContent("news/categories/b/_index.md", `
|
|
|
|
---
|
|
|
|
title: "This is B"
|
|
|
|
---
|
2018-12-29 04:35:46 -05:00
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("news/categories/f/g/h/_index.md", `
|
|
|
|
---
|
|
|
|
title: "This is H"
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("t1/t2/t3s/t4/t5/_index.md", `
|
|
|
|
---
|
|
|
|
title: "This is T5"
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("s1/s2/s3s/_index.md", `
|
|
|
|
---
|
|
|
|
title: "This is S3s"
|
|
|
|
---
|
2018-12-29 04:14:37 -05:00
|
|
|
`)
|
|
|
|
|
|
|
|
b.CreateSites().Build(BuildCfg{})
|
|
|
|
|
2018-12-29 04:35:46 -05:00
|
|
|
s := b.H.Sites[0]
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
filterbyKind := func(kind string) page.Pages {
|
|
|
|
var pages page.Pages
|
|
|
|
for _, p := range s.Pages() {
|
|
|
|
if p.Kind() == kind {
|
|
|
|
pages = append(pages, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pages
|
|
|
|
}
|
|
|
|
|
|
|
|
ta := filterbyKind(page.KindTaxonomy)
|
|
|
|
te := filterbyKind(page.KindTaxonomyTerm)
|
2018-12-29 04:35:46 -05:00
|
|
|
|
2019-08-10 15:05:17 -04:00
|
|
|
b.Assert(len(te), qt.Equals, 4)
|
|
|
|
b.Assert(len(ta), qt.Equals, 7)
|
2018-12-29 04:35:46 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/news/categories/a/index.html", "Taxonomy List Page 1|a|Hello|https://example.com/news/categories/a/|")
|
2018-12-29 04:14:37 -05:00
|
|
|
b.AssertFileContent("public/news/categories/b/index.html", "Taxonomy List Page 1|This is B|Hello|https://example.com/news/categories/b/|")
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/news/categories/d/e/index.html", "Taxonomy List Page 1|d/e|Hello|https://example.com/news/categories/d/e/|")
|
2018-12-29 04:35:46 -05:00
|
|
|
b.AssertFileContent("public/news/categories/f/g/h/index.html", "Taxonomy List Page 1|This is H|Hello|https://example.com/news/categories/f/g/h/|")
|
|
|
|
b.AssertFileContent("public/t1/t2/t3s/t4/t5/index.html", "Taxonomy List Page 1|This is T5|Hello|https://example.com/t1/t2/t3s/t4/t5/|")
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/t1/t2/t3s/t4/t5/t6/index.html", "Taxonomy List Page 1|t4/t5/t6|Hello|https://example.com/t1/t2/t3s/t4/t5/t6/|")
|
2018-12-29 04:35:46 -05:00
|
|
|
|
|
|
|
b.AssertFileContent("public/news/categories/index.html", "Taxonomy Term Page 1|News/Categories|Hello|https://example.com/news/categories/|")
|
|
|
|
b.AssertFileContent("public/t1/t2/t3s/index.html", "Taxonomy Term Page 1|T1/T2/T3s|Hello|https://example.com/t1/t2/t3s/|")
|
|
|
|
b.AssertFileContent("public/s1/s2/s3s/index.html", "Taxonomy Term Page 1|This is S3s|Hello|https://example.com/s1/s2/s3s/|")
|
|
|
|
|
2018-12-29 04:14:37 -05:00
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
// https://github.com/gohugoio/hugo/issues/5719
|
|
|
|
func TestTaxonomiesNextGenLoops(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `
|
|
|
|
<h1>Tags</h1>
|
|
|
|
<ul>
|
|
|
|
{{ range .Site.Taxonomies.tags }}
|
|
|
|
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
|
|
|
|
{{ end }}
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("_default/terms.html", `
|
|
|
|
<h1>Terms</h1>
|
|
|
|
<ul>
|
|
|
|
{{ range .Data.Terms.Alphabetical }}
|
|
|
|
<li><a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a> {{ .Count }}</li>
|
|
|
|
{{ end }}
|
|
|
|
</ul>
|
|
|
|
`)
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
b.WithContent(fmt.Sprintf("page%d.md", i+1), `
|
|
|
|
---
|
|
|
|
Title: "Taxonomy!"
|
|
|
|
tags: ["Hugo Rocks!", "Rocks I say!" ]
|
|
|
|
categories: ["This is Cool", "And new" ]
|
|
|
|
---
|
|
|
|
|
|
|
|
Content.
|
|
|
|
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.CreateSites().Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", `<li><a href="http://example.com/tags/hugo-rocks/">Hugo Rocks!</a> 10</li>`)
|
|
|
|
b.AssertFileContent("public/categories/index.html", `<li><a href="http://example.com/categories/this-is-cool/">This is Cool</a> 10</li>`)
|
|
|
|
b.AssertFileContent("public/tags/index.html", `<li><a href="http://example.com/tags/rocks-i-say/">Rocks I say!</a> 10</li>`)
|
|
|
|
|
|
|
|
}
|
2019-08-15 03:47:25 -04:00
|
|
|
|
|
|
|
// Issue 6213
|
|
|
|
func TestTaxonomiesNotForDrafts(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithContent("draft.md", `---
|
|
|
|
title: "Draft"
|
|
|
|
draft: true
|
|
|
|
categories: ["drafts"]
|
|
|
|
---
|
|
|
|
|
|
|
|
`,
|
|
|
|
"regular.md", `---
|
|
|
|
title: "Not Draft"
|
|
|
|
categories: ["regular"]
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
s := b.H.Sites[0]
|
|
|
|
|
|
|
|
b.Assert(b.CheckExists("public/categories/regular/index.html"), qt.Equals, true)
|
|
|
|
b.Assert(b.CheckExists("public/categories/drafts/index.html"), qt.Equals, false)
|
|
|
|
|
|
|
|
reg, _ := s.getPageNew(nil, "categories/regular")
|
|
|
|
dra, _ := s.getPageNew(nil, "categories/draft")
|
|
|
|
b.Assert(reg, qt.Not(qt.IsNil))
|
|
|
|
b.Assert(dra, qt.IsNil)
|
|
|
|
|
|
|
|
}
|
2019-08-15 12:25:21 -04:00
|
|
|
|
|
|
|
func TestTaxonomiesIndexDraft(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithContent(
|
|
|
|
"categories/_index.md", `---
|
|
|
|
title: "The Categories"
|
|
|
|
draft: true
|
|
|
|
---
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
Content.
|
2019-08-15 12:25:21 -04:00
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
`,
|
|
|
|
"page.md", `---
|
|
|
|
title: "The Page"
|
|
|
|
categories: ["cool"]
|
|
|
|
---
|
|
|
|
|
|
|
|
Content.
|
|
|
|
|
|
|
|
`,
|
|
|
|
)
|
2019-08-15 12:25:21 -04:00
|
|
|
|
|
|
|
b.WithTemplates("index.html", `
|
|
|
|
{{ range .Site.Pages }}
|
|
|
|
{{ .RelPermalink }}|{{ .Title }}|{{ .WordCount }}|{{ .Content }}|
|
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
b.AssertFileContentFn("public/index.html", func(s string) bool {
|
|
|
|
return !strings.Contains(s, "categories")
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-22 12:22:40 -05:00
|
|
|
// https://github.com/gohugoio/hugo/issues/6927
|
|
|
|
func TestTaxonomiesHomeDraft(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithContent(
|
|
|
|
"_index.md", `---
|
|
|
|
title: "Home"
|
|
|
|
draft: true
|
|
|
|
---
|
|
|
|
|
|
|
|
Content.
|
|
|
|
|
|
|
|
`,
|
|
|
|
"posts/_index.md", `---
|
|
|
|
title: "Posts"
|
|
|
|
draft: true
|
|
|
|
---
|
|
|
|
|
|
|
|
Content.
|
|
|
|
|
|
|
|
`,
|
|
|
|
"posts/page.md", `---
|
|
|
|
title: "The Page"
|
|
|
|
categories: ["cool"]
|
|
|
|
---
|
|
|
|
|
|
|
|
Content.
|
|
|
|
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
|
|
|
b.WithTemplates("index.html", `
|
|
|
|
NO HOME FOR YOU
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.Assert(b.CheckExists("public/index.html"), qt.Equals, false)
|
|
|
|
b.Assert(b.CheckExists("public/categories/index.html"), qt.Equals, false)
|
|
|
|
b.Assert(b.CheckExists("public/posts/index.html"), qt.Equals, false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-10 05:26:34 -04:00
|
|
|
// https://github.com/gohugoio/hugo/issues/6173
|
|
|
|
func TestTaxonomiesWithBundledResources(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithTemplates("_default/list.html", `
|
|
|
|
List {{ .Title }}:
|
|
|
|
{{ range .Resources }}
|
|
|
|
Resource: {{ .RelPermalink }}|{{ .MediaType }}
|
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("p1.md", `---
|
|
|
|
title: Page
|
|
|
|
categories: ["funny"]
|
|
|
|
---
|
|
|
|
`,
|
|
|
|
"categories/_index.md", "---\ntitle: Categories Page\n---",
|
|
|
|
"categories/data.json", "Category data",
|
|
|
|
"categories/funny/_index.md", "---\ntitle: Funnny Category\n---",
|
|
|
|
"categories/funny/funnydata.json", "Category funny data",
|
|
|
|
)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/categories/index.html", `Resource: /categories/data.json|application/json`)
|
|
|
|
b.AssertFileContent("public/categories/funny/index.html", `Resource: /categories/funny/funnydata.json|application/json`)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTaxonomiesRemoveOne(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t).Running()
|
|
|
|
b.WithTemplates("index.html", `
|
|
|
|
{{ $cats := .Site.Taxonomies.categories.cats }}
|
|
|
|
{{ if $cats }}
|
|
|
|
Len cats: {{ len $cats }}
|
|
|
|
{{ range $cats }}
|
|
|
|
Cats:|{{ .Page.RelPermalink }}|
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
{{ $funny := .Site.Taxonomies.categories.funny }}
|
|
|
|
{{ if $funny }}
|
|
|
|
Len funny: {{ len $funny }}
|
|
|
|
{{ range $funny }}
|
|
|
|
Funny:|{{ .Page.RelPermalink }}|
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("p1.md", `---
|
|
|
|
title: Page
|
|
|
|
categories: ["funny", "cats"]
|
|
|
|
---
|
|
|
|
`, "p2.md", `---
|
|
|
|
title: Page2
|
|
|
|
categories: ["funny", "cats"]
|
|
|
|
---
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", `
|
|
|
|
Len cats: 2
|
|
|
|
Len funny: 2
|
|
|
|
Cats:|/p1/|
|
|
|
|
Cats:|/p2/|
|
|
|
|
Funny:|/p1/|
|
|
|
|
Funny:|/p2/|`)
|
|
|
|
|
|
|
|
// Remove one category from one of the pages.
|
|
|
|
b.EditFiles("content/p1.md", `---
|
|
|
|
title: Page
|
|
|
|
categories: ["funny"]
|
|
|
|
---
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", `
|
|
|
|
Len cats: 1
|
|
|
|
Len funny: 2
|
|
|
|
Cats:|/p2/|
|
|
|
|
Funny:|/p1/|
|
|
|
|
Funny:|/p2/|`)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://github.com/gohugoio/hugo/issues/6590
|
|
|
|
func TestTaxonomiesListPages(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithTemplates("_default/list.html", `
|
|
|
|
|
|
|
|
{{ template "print-taxo" "categories.cats" }}
|
|
|
|
{{ template "print-taxo" "categories.funny" }}
|
|
|
|
|
|
|
|
{{ define "print-taxo" }}
|
|
|
|
{{ $node := index site.Taxonomies (split $ ".") }}
|
|
|
|
{{ if $node }}
|
|
|
|
Len {{ $ }}: {{ len $node }}
|
|
|
|
{{ range $node }}
|
|
|
|
{{ $ }}:|{{ .Page.RelPermalink }}|
|
|
|
|
{{ end }}
|
|
|
|
{{ else }}
|
|
|
|
{{ $ }} not found.
|
|
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("_index.md", `---
|
|
|
|
title: Home
|
|
|
|
categories: ["funny", "cats"]
|
|
|
|
---
|
|
|
|
`, "blog/p1.md", `---
|
|
|
|
title: Page1
|
|
|
|
categories: ["funny"]
|
|
|
|
---
|
|
|
|
`, "blog/_index.md", `---
|
|
|
|
title: Blog Section
|
|
|
|
categories: ["cats"]
|
|
|
|
---
|
|
|
|
`,
|
|
|
|
)
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/index.html", `
|
|
|
|
|
|
|
|
Len categories.cats: 2
|
|
|
|
categories.cats:|/blog/|
|
|
|
|
categories.cats:|/|
|
|
|
|
|
|
|
|
Len categories.funny: 2
|
|
|
|
categories.funny:|/|
|
|
|
|
categories.funny:|/blog/p1/|
|
|
|
|
`)
|
2019-08-15 12:25:21 -04:00
|
|
|
|
|
|
|
}
|
2020-02-18 10:16:09 -05:00
|
|
|
|
2020-02-18 12:49:11 -05:00
|
|
|
func TestTaxonomiesPageCollections(t *testing.T) {
|
2020-02-18 10:16:09 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
2020-02-19 03:16:27 -05:00
|
|
|
b.WithContent(
|
|
|
|
"_index.md", `---
|
|
|
|
title: "Home Sweet Home"
|
|
|
|
categories: [ "dogs", "gorillas"]
|
|
|
|
---
|
|
|
|
`,
|
|
|
|
"section/_index.md", `---
|
|
|
|
title: "Section"
|
|
|
|
categories: [ "cats", "dogs", "birds"]
|
|
|
|
---
|
|
|
|
`,
|
|
|
|
"section/p1.md", `---
|
2020-02-18 12:49:11 -05:00
|
|
|
title: "Page1"
|
|
|
|
categories: ["funny", "cats"]
|
|
|
|
---
|
2020-02-19 03:16:27 -05:00
|
|
|
`, "section/p2.md", `---
|
2020-02-18 12:49:11 -05:00
|
|
|
title: "Page2"
|
2020-02-18 10:16:09 -05:00
|
|
|
categories: ["funny"]
|
|
|
|
---
|
2020-02-18 12:49:11 -05:00
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("index.html", `
|
2020-02-19 03:16:27 -05:00
|
|
|
{{ $home := site.Home }}
|
|
|
|
{{ $section := site.GetPage "section" }}
|
2020-02-18 12:49:11 -05:00
|
|
|
{{ $categories := site.GetPage "categories" }}
|
|
|
|
{{ $funny := site.GetPage "categories/funny" }}
|
|
|
|
{{ $cats := site.GetPage "categories/cats" }}
|
2020-02-19 03:16:27 -05:00
|
|
|
{{ $p1 := site.GetPage "section/p1" }}
|
2020-02-18 12:49:11 -05:00
|
|
|
|
|
|
|
Categories Pages: {{ range $categories.Pages}}{{.RelPermalink }}|{{ end }}:END
|
|
|
|
Funny Pages: {{ range $funny.Pages}}{{.RelPermalink }}|{{ end }}:END
|
|
|
|
Cats Pages: {{ range $cats.Pages}}{{.RelPermalink }}|{{ end }}:END
|
2020-02-19 03:16:27 -05:00
|
|
|
P1 Terms: {{ range $p1.GetTerms "categories" }}{{.RelPermalink }}|{{ end }}:END
|
|
|
|
Section Terms: {{ range $section.GetTerms "categories" }}{{.RelPermalink }}|{{ end }}:END
|
|
|
|
Home Terms: {{ range $home.GetTerms "categories" }}{{.RelPermalink }}|{{ end }}:END
|
2020-02-20 08:03:56 -05:00
|
|
|
Category Paginator {{ range $categories.Paginator.Pages }}{{ .RelPermalink }}|{{ end }}:END
|
|
|
|
Cats Paginator {{ range $cats.Paginator.Pages }}{{ .RelPermalink }}|{{ end }}:END
|
|
|
|
|
2020-02-18 10:16:09 -05:00
|
|
|
`)
|
2020-03-20 09:35:41 -04:00
|
|
|
b.WithTemplatesAdded("404.html", `
|
|
|
|
404 Terms: {{ range .GetTerms "categories" }}{{.RelPermalink }}|{{ end }}:END
|
|
|
|
`)
|
2020-02-18 10:16:09 -05:00
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
cat := b.GetPage("categories")
|
|
|
|
funny := b.GetPage("categories/funny")
|
|
|
|
|
|
|
|
b.Assert(cat, qt.Not(qt.IsNil))
|
|
|
|
b.Assert(funny, qt.Not(qt.IsNil))
|
|
|
|
|
|
|
|
b.Assert(cat.Parent().IsHome(), qt.Equals, true)
|
|
|
|
b.Assert(funny.Parent(), qt.Equals, cat)
|
|
|
|
|
2020-02-18 12:49:11 -05:00
|
|
|
b.AssertFileContent("public/index.html", `
|
2020-02-20 08:03:56 -05:00
|
|
|
Categories Pages: /categories/birds/|/categories/cats/|/categories/dogs/|/categories/funny/|/categories/gorillas/|:END
|
|
|
|
Funny Pages: /section/p1/|/section/p2/|:END
|
|
|
|
Cats Pages: /section/p1/|/section/|:END
|
|
|
|
P1 Terms: /categories/cats/|/categories/funny/|:END
|
|
|
|
Section Terms: /categories/birds/|/categories/cats/|/categories/dogs/|:END
|
|
|
|
Home Terms: /categories/dogs/|/categories/gorillas/|:END
|
|
|
|
Cats Paginator /section/p1/|/section/|:END
|
|
|
|
Category Paginator /categories/birds/|/categories/cats/|/categories/dogs/|/categories/funny/|/categories/gorillas/|:END
|
2020-02-18 12:49:11 -05:00
|
|
|
`)
|
2020-03-20 09:35:41 -04:00
|
|
|
b.AssertFileContent("public/404.html", "\n404 Terms: :END\n\t")
|
2020-02-19 03:16:27 -05:00
|
|
|
b.AssertFileContent("public/categories/funny/index.xml", `<link>http://example.com/section/p1/</link>`)
|
2020-02-18 10:55:30 -05:00
|
|
|
b.AssertFileContent("public/categories/index.xml", `<link>http://example.com/categories/funny/</link>`)
|
2020-02-18 10:16:09 -05:00
|
|
|
|
|
|
|
}
|