diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-06-16 15:43:50 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-06-18 09:09:56 +0200 |
commit | fc045e12a953aac88b942c25b958c5c0554b252b (patch) | |
tree | ad8e171d0730f55eb9a531c1a9f0a8dfb51065ad /hugolib | |
parent | 9679023f2b0d7c55b70f23fd94603f301a841079 (diff) | |
download | hugo-fc045e12a953aac88b942c25b958c5c0554b252b.tar.gz hugo-fc045e12a953aac88b942c25b958c5c0554b252b.zip |
Rename taxonomy kinds from taxonomy to term, taxonomyTerm to taxonomy
And we have taken great measures to limit potential site breakage:
* For `disableKinds` and `outputs` we try to map from old to new values if possible, if not we print an ERROR that can be toggled off if not relevant.
* The layout lookup is mostly compatible with more options for the new `term` kind.
That leaves:
* Where queries in site.Pages using taxonomy/taxonomyTerm Kind values as filter.
* Other places where these kind value are used in the templates (classes etc.)
Fixes #6911
Fixes #7395
Diffstat (limited to 'hugolib')
27 files changed, 294 insertions, 86 deletions
diff --git a/hugolib/breaking_changes_test.go b/hugolib/breaking_changes_test.go new file mode 100644 index 000000000..c935d6e93 --- /dev/null +++ b/hugolib/breaking_changes_test.go @@ -0,0 +1,141 @@ +// Copyright 2020 The Hugo Authors. All rights reserved. +// +// 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. + +package hugolib + +import ( + "fmt" + "testing" + + qt "github.com/frankban/quicktest" +) + +func Test073(t *testing.T) { + + asertDisabledTaxonomyAndTerm := func(b *sitesBuilder, taxonomy, term bool) { + b.Assert(b.CheckExists("public/tags/index.html"), qt.Equals, taxonomy) + b.Assert(b.CheckExists("public/tags/tag1/index.html"), qt.Equals, term) + + } + + assertOutputTaxonomyAndTerm := func(b *sitesBuilder, taxonomy, term bool) { + b.Assert(b.CheckExists("public/tags/index.json"), qt.Equals, taxonomy) + b.Assert(b.CheckExists("public/tags/tag1/index.json"), qt.Equals, term) + } + + for _, this := range []struct { + name string + config string + assert func(err error, out string, b *sitesBuilder) + }{ + { + "Outputs for both taxonomy and taxonomyTerm", + `[outputs] + taxonomy = ["JSON"] + taxonomyTerm = ["JSON"] + +`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.IsNil) + assertOutputTaxonomyAndTerm(b, true, true) + + }, + }, + { + "Outputs for taxonomyTerm", + `[outputs] +taxonomyTerm = ["JSON"] + +`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.IsNil) + assertOutputTaxonomyAndTerm(b, true, false) + + }, + }, + { + "Outputs for taxonomy only", + `[outputs] +taxonomy = ["JSON"] + +`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.Not(qt.IsNil)) + b.Assert(out, qt.Contains, `ignoreErrors = ["error-output-taxonomy"]`) + + }, + }, + { + "Outputs for taxonomy only, ignore error", + ` +ignoreErrors = ["error-output-taxonomy"] +[outputs] +taxonomy = ["JSON"] + +`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.IsNil) + assertOutputTaxonomyAndTerm(b, true, false) + + }, + }, + { + "Disable both taxonomy and taxonomyTerm", + `disableKinds = ["taxonomy", "taxonomyTerm"]`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.IsNil) + asertDisabledTaxonomyAndTerm(b, false, false) + + }, + }, + { + "Disable only taxonomyTerm", + `disableKinds = ["taxonomyTerm"]`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.IsNil) + asertDisabledTaxonomyAndTerm(b, false, true) + + }, + }, + { + "Disable only taxonomy", + `disableKinds = ["taxonomy"]`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.Not(qt.IsNil)) + b.Assert(out, qt.Contains, `ignoreErrors = ["error-disable-taxonomy"]`) + }, + }, + { + "Disable only taxonomy, ignore error", + `disableKinds = ["taxonomy"] + ignoreErrors = ["error-disable-taxonomy"]`, + func(err error, out string, b *sitesBuilder) { + b.Assert(err, qt.IsNil) + asertDisabledTaxonomyAndTerm(b, false, true) + }, + }, + } { + + t.Run(this.name, func(t *testing.T) { + b := newTestSitesBuilder(t).WithConfigFile("toml", this.config) + b.WithTemplatesAdded("_default/list.json", "JSON") + out, err := captureStdout(func() error { + return b.BuildE(BuildCfg{}) + }) + fmt.Println(out) + this.assert(err, out, b) + }) + + } + +} diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index dd3aa72a6..33fc7ceec 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -61,13 +61,13 @@ func TestCascade(t *testing.T) { b.Build(BuildCfg{}) b.AssertFileContent("public/index.html", ` -12|taxonomy|categories/cool/_index.md|Cascade Category|cat.png|categories|HTML-| -12|taxonomy|categories/catsect1|catsect1|cat.png|categories|HTML-| -12|taxonomy|categories/funny|funny|cat.png|categories|HTML-| -12|taxonomyTerm|categories/_index.md|My Categories|cat.png|categories|HTML-| -32|taxonomy|categories/sad/_index.md|Cascade Category|sad.png|categories|HTML-| -42|taxonomy|tags/blue|blue|home.png|tags|HTML-| -42|taxonomyTerm|tags|Cascade Home|home.png|tags|HTML-| +12|term|categories/cool/_index.md|Cascade Category|cat.png|categories|HTML-| +12|term|categories/catsect1|catsect1|cat.png|categories|HTML-| +12|term|categories/funny|funny|cat.png|categories|HTML-| +12|taxonomy|categories/_index.md|My Categories|cat.png|categories|HTML-| +32|term|categories/sad/_index.md|Cascade Category|sad.png|categories|HTML-| +42|term|tags/blue|blue|home.png|tags|HTML-| +42|taxonomy|tags|Cascade Home|home.png|tags|HTML-| 42|section|sectnocontent|Cascade Home|home.png|sectnocontent|HTML-| 42|section|sect3|Cascade Home|home.png|sect3|HTML-| 42|page|bundle1/index.md|Cascade Home|home.png|page|HTML-| @@ -77,7 +77,7 @@ func TestCascade(t *testing.T) { 42|page|sect3/p1.md|Cascade Home|home.png|sect3|HTML-| 42|page|sectnocontent/p1.md|Cascade Home|home.png|sectnocontent|HTML-| 42|section|sectnofrontmatter/_index.md|Cascade Home|home.png|sectnofrontmatter|HTML-| -42|taxonomy|tags/green|green|home.png|tags|HTML-| +42|term|tags/green|green|home.png|tags|HTML-| 42|home|_index.md|Home|home.png|page|HTML-| 42|page|p1.md|p1|home.png|page|HTML-| 42|section|sect1/_index.md|Sect1|sect1.png|stype|HTML-| diff --git a/hugolib/content_map.go b/hugolib/content_map.go index 8af553478..43ad7745d 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -274,13 +274,13 @@ type contentBundleViewInfo struct { func (c *contentBundleViewInfo) kind() string { if c.termKey != "" { - return page.KindTaxonomy + return page.KindTerm } - return page.KindTaxonomyTerm + return page.KindTaxonomy } func (c *contentBundleViewInfo) sections() []string { - if c.kind() == page.KindTaxonomyTerm { + if c.kind() == page.KindTaxonomy { return []string{c.name.plural} } diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index b5165b2a5..b32f808c9 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -106,7 +106,7 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB sections := s.sectionsFromFile(f) kind := s.kindFromFileInfoOrSections(f, sections) - if kind == page.KindTaxonomy { + if kind == page.KindTerm { s.PathSpec.MakePathsSanitized(sections) } @@ -535,7 +535,7 @@ func (m *pageMap) assembleTaxonomies() error { } } else { title := "" - if kind == page.KindTaxonomy { + if kind == page.KindTerm { title = n.viewInfo.term() } n.p = m.s.newPage(n, parent.p.bucket, kind, title, sections...) diff --git a/hugolib/content_map_test.go b/hugolib/content_map_test.go index 9ec30201a..42a69c26b 100644 --- a/hugolib/content_map_test.go +++ b/hugolib/content_map_test.go @@ -451,8 +451,8 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}| Pages: /blog/page3/|/blog/subsection/|/blog/page2/|/blog/page1/|/blog/bundle/| Sections: /blog/|/docs/| Categories: /categories/funny/; funny; 11| - Category Terms: taxonomyTerm: /categories/funny/; funny; 11| - Category Funny: taxonomy; funny: /blog/subsection/page4/;|/blog/page3/;|/blog/subsection/;|/blog/page2/;|/blog/page1/;|/blog/subsection/page5/;|/docs/page6/;|/blog/bundle/;|;| + Category Terms: taxonomy: /categories/funny/; funny; 11| + Category Funny: term; funny: /blog/subsection/page4/;|/blog/page3/;|/blog/subsection/;|/blog/page2/;|/blog/page1/;|/blog/subsection/page5/;|/docs/page6/;|/blog/bundle/;|;| Pag Num Pages: 7 Pag Blog Num Pages: 4 Blog Num RegularPages: 4 diff --git a/hugolib/disableKinds_test.go b/hugolib/disableKinds_test.go index 87c2b5d3d..4f12ee2b5 100644 --- a/hugolib/disableKinds_test.go +++ b/hugolib/disableKinds_test.go @@ -28,6 +28,7 @@ func TestDisable(t *testing.T) { config := fmt.Sprintf(` baseURL = "http://example.com/blog" enableRobotsTXT = true +ignoreErrors = ["error-disable-taxonomy"] disableKinds = [%q] `, disableKind) @@ -141,7 +142,7 @@ title: Headless Local Lists Sub b.Assert(len(s.Taxonomies()["categories"]), qt.Equals, 0) }) - disableKind = page.KindTaxonomy + disableKind = page.KindTerm c.Run("Disable "+disableKind, func(c *qt.C) { b := newSitesBuilder(c, disableKind) b.Build(BuildCfg{}) @@ -153,7 +154,7 @@ title: Headless Local Lists Sub b.Assert(getPage(b, "/categories/mycat"), qt.IsNil) }) - disableKind = page.KindTaxonomyTerm + disableKind = page.KindTaxonomy c.Run("Disable "+disableKind, func(c *qt.C) { b := newSitesBuilder(c, disableKind) b.Build(BuildCfg{}) @@ -319,7 +320,7 @@ title: Headless Local Lists Sub // https://github.com/gohugoio/hugo/issues/6897#issuecomment-587947078 func TestDisableRSSWithRSSInCustomOutputs(t *testing.T) { b := newTestSitesBuilder(t).WithConfigFile("toml", ` -disableKinds = ["taxonomy", "taxonomyTerm", "RSS"] +disableKinds = ["term", "taxonomy", "RSS"] [outputs] home = [ "HTML", "RSS" ] `).Build(BuildCfg{}) diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index 16de27b0d..e71e48d41 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -443,8 +443,8 @@ func applyDeps(cfg deps.DepsCfg, sites ...*Site) error { contentMap: newContentMap(contentMapConfig{ lang: s.Lang(), taxonomyConfig: s.siteCfg.taxonomiesConfig.Values(), - taxonomyDisabled: !s.isEnabled(page.KindTaxonomy), - taxonomyTermDisabled: !s.isEnabled(page.KindTaxonomyTerm), + taxonomyDisabled: !s.isEnabled(page.KindTerm), + taxonomyTermDisabled: !s.isEnabled(page.KindTaxonomy), pageDisabled: !s.isEnabled(page.KindPage), }), s: s, @@ -493,6 +493,9 @@ func applyDeps(cfg deps.DepsCfg, sites ...*Site) error { // NewHugoSites creates HugoSites from the given config. func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) { + if cfg.Logger == nil { + cfg.Logger = loggers.NewErrorLogger() + } sites, err := createSitesFromConfig(cfg) if err != nil { return nil, errors.Wrap(err, "from config") diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 59f228fef..84655c1f2 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -339,14 +339,14 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { nnSite := sites[2] c.Assert(nnSite.language.Lang, qt.Equals, "nn") - taxNn := nnSite.getPage(page.KindTaxonomyTerm, "lag") + taxNn := nnSite.getPage(page.KindTaxonomy, "lag") c.Assert(taxNn, qt.Not(qt.IsNil)) c.Assert(len(taxNn.Translations()), qt.Equals, 1) c.Assert(taxNn.Translations()[0].Language().Lang, qt.Equals, "nb") - taxTermNn := nnSite.getPage(page.KindTaxonomy, "lag", "sogndal") + taxTermNn := nnSite.getPage(page.KindTerm, "lag", "sogndal") c.Assert(taxTermNn, qt.Not(qt.IsNil)) - c.Assert(nnSite.getPage(page.KindTaxonomy, "LAG", "SOGNDAL"), qt.Equals, taxTermNn) + c.Assert(nnSite.getPage(page.KindTerm, "LAG", "SOGNDAL"), qt.Equals, taxTermNn) c.Assert(len(taxTermNn.Translations()), qt.Equals, 1) c.Assert(taxTermNn.Translations()[0].Language().Lang, qt.Equals, "nb") diff --git a/hugolib/hugo_smoke_test.go b/hugolib/hugo_smoke_test.go index 406255d51..5aa508290 100644 --- a/hugolib/hugo_smoke_test.go +++ b/hugolib/hugo_smoke_test.go @@ -27,7 +27,7 @@ func TestHello(t *testing.T) { b := newTestSitesBuilder(t) b.WithConfigFile("toml", ` baseURL="https://example.org" -disableKinds = ["taxonomy", "taxonomyTerm", "section", "page"] +disableKinds = ["term", "taxonomy", "section", "page"] `) b.WithContent("p1", ` --- diff --git a/hugolib/page.go b/hugolib/page.go index baf5e7f69..28ef1e156 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -212,9 +212,9 @@ func (p *pageState) RegularPages() page.Pages { switch p.Kind() { case page.KindPage: - case page.KindSection, page.KindHome, page.KindTaxonomyTerm: + case page.KindSection, page.KindHome, page.KindTaxonomy: pages = p.getPages() - case page.KindTaxonomy: + case page.KindTerm: all := p.Pages() for _, p := range all { if p.IsPage() { @@ -240,9 +240,9 @@ func (p *pageState) Pages() page.Pages { case page.KindPage: case page.KindSection, page.KindHome: pages = p.getPagesAndSections() - case page.KindTaxonomy: + case page.KindTerm: pages = p.bucket.getTaxonomyEntries() - case page.KindTaxonomyTerm: + case page.KindTaxonomy: pages = p.bucket.getTaxonomies() default: pages = p.s.Pages() @@ -436,7 +436,7 @@ func (p *pageState) getLayoutDescriptor() output.LayoutDescriptor { if len(sections) > 0 { section = sections[0] } - case page.KindTaxonomyTerm, page.KindTaxonomy: + case page.KindTaxonomy, page.KindTerm: b := p.getTreeRef().n section = b.viewInfo.name.singular default: diff --git a/hugolib/page__data.go b/hugolib/page__data.go index 131bf8d5d..9fc97f8f6 100644 --- a/hugolib/page__data.go +++ b/hugolib/page__data.go @@ -35,7 +35,7 @@ func (p *pageData) Data() interface{} { } switch p.Kind() { - case page.KindTaxonomy: + case page.KindTerm: b := p.treeRef.n name := b.viewInfo.name termKey := b.viewInfo.termKey @@ -46,7 +46,7 @@ func (p *pageData) Data() interface{} { p.data["Singular"] = name.singular p.data["Plural"] = name.plural p.data["Term"] = b.viewInfo.term() - case page.KindTaxonomyTerm: + case page.KindTaxonomy: b := p.treeRef.n name := b.viewInfo.name diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index 435b95473..c7226c6f2 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -52,7 +52,7 @@ type pageMeta struct { // in the different page collections. This can, as an example, be used // to to filter regular pages, find sections etc. // Kind will, for the pages available to the templates, be one of: - // page, home, section, taxonomy and taxonomyTerm. + // page, home, section, taxonomy and term. // It is of string type to make it easy to reason about in // the templates. kind string @@ -678,11 +678,11 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error { } else { p.title = sectionName } - case page.KindTaxonomy: + case page.KindTerm: // TODO(bep) improve key := p.sections[len(p.sections)-1] p.title = strings.Replace(p.s.titleFunc(key), "-", " ", -1) - case page.KindTaxonomyTerm: + case page.KindTaxonomy: p.title = p.s.titleFunc(p.sections[0]) case kind404: p.title = "404 Page not found" diff --git a/hugolib/page__paginator.go b/hugolib/page__paginator.go index 942597e04..5948735d1 100644 --- a/hugolib/page__paginator.go +++ b/hugolib/page__paginator.go @@ -89,7 +89,7 @@ func (p *pagePaginator) Paginator(options ...interface{}) (*page.Pager, error) { // section. To avoid the default paginators for the home page // changing in the wild, we make this a special case. pages = p.source.s.RegularPages() - case page.KindTaxonomy, page.KindTaxonomyTerm: + case page.KindTerm, page.KindTaxonomy: pages = p.source.Pages() default: pages = p.source.RegularPages() diff --git a/hugolib/page__paths.go b/hugolib/page__paths.go index 5dc42bc2a..d0bf26961 100644 --- a/hugolib/page__paths.go +++ b/hugolib/page__paths.go @@ -147,7 +147,7 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target // the permalink configuration values are likely to be redundant, e.g. // naively expanding /category/:slug/ would give /category/categories/ for // the "categories" page.KindTaxonomyTerm. - if p.Kind() == page.KindPage || p.Kind() == page.KindTaxonomy { + if p.Kind() == page.KindPage || p.Kind() == page.KindTerm { opath, err := d.ResourceSpec.Permalinks.Expand(p.Section(), p) if err != nil { return desc, err diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index d2ef00e76..a617ad384 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -171,7 +171,7 @@ func (pt pageTree) Parent() page.Page { tree := p.getTreeRef() - if tree == nil || pt.p.Kind() == page.KindTaxonomyTerm { + if tree == nil || pt.p.Kind() == page.KindTaxonomy { return pt.p.s.home } diff --git a/hugolib/page_kinds.go b/hugolib/page_kinds.go index 4f000c3e5..683d12c1b 100644 --- a/hugolib/page_kinds.go +++ b/hugolib/page_kinds.go @@ -22,7 +22,7 @@ import ( var ( // This is all the kinds we can expect to find in .Site.Pages. - allKindsInPages = []string{page.KindPage, page.KindHome, page.KindSection, page.KindTaxonomy, page.KindTaxonomyTerm} + allKindsInPages = []string{page.KindPage, page.KindHome, page.KindSection, page.KindTerm, page.KindTaxonomy} ) const ( diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go index 4566c5f97..fa420a025 100644 --- a/hugolib/pagebundler_test.go +++ b/hugolib/pagebundler_test.go @@ -1145,7 +1145,7 @@ func TestPageBundlerPartialTranslations(t *testing.T) { baseURL = "https://example.org" defaultContentLanguage = "en" defaultContentLanguageInSubDir = true -disableKinds = ["taxonomyTerm", "taxonomy"] +disableKinds = ["taxonomy", "term"] [languages] [languages.nn] languageName = "Nynorsk" diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index bb846da85..b9623eb34 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -279,8 +279,8 @@ func TestGetPage(t *testing.T) { {"Abs, ignore context, page deep", "NoPage", sec3, []string{"/subsect/deep.md"}, ""}, // Taxonomies - {"Taxonomy term", page.KindTaxonomyTerm, nil, []string{"categories"}, "Categories"}, - {"Taxonomy", page.KindTaxonomy, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"}, + {"Taxonomy term", page.KindTaxonomy, nil, []string{"categories"}, "Categories"}, + {"Taxonomy", page.KindTerm, nil, []string{"categories/hugo", "categories/Hugo"}, "Hugo"}, // Bundle variants {"Bundle regular", page.KindPage, nil, []string{"sect3/b1", "sect3/b1/index.md", "sect3/b1/index.en.md"}, "b1 bundle"}, diff --git a/hugolib/resource_chain_babel_test.go b/hugolib/resource_chain_babel_test.go index c9ddb2140..d3351dfd4 100644 --- a/hugolib/resource_chain_babel_test.go +++ b/hugolib/resource_chain_babel_test.go @@ -82,7 +82,7 @@ class Car { v := viper.New() v.Set("workingDir", workDir) - v.Set("disableKinds", []string{"taxonomyTerm", "taxonomy", "page"}) + v.Set("disableKinds", []string{"taxonomy", "term", "page"}) b := newTestSitesBuilder(t).WithLogger(loggers.NewWarningLogger()) // Need to use OS fs for this. diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index 67641bdb8..c687ca342 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -895,7 +895,7 @@ h1 { newTestBuilder := func(v *viper.Viper) *sitesBuilder { v.Set("workingDir", workDir) - v.Set("disableKinds", []string{"taxonomyTerm", "taxonomy", "page"}) + v.Set("disableKinds", []string{"taxonomy", "term", "page"}) b := newTestSitesBuilder(t).WithLogger(loggers.NewWarningLogger()) // Need to use OS fs for this. b.Fs = hugofs.NewDefault(v) diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 8bb468465..961450cb8 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -626,7 +626,7 @@ baseURL = "http://example.com/blog" paginate = 1 -disableKinds = ["section", "taxonomy", "taxonomyTerm", "RSS", "sitemap", "robotsTXT", "404"] +disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"] [outputs] home = [ "HTML", "AMP", "Calendar" ] diff --git a/hugolib/site.go b/hugolib/site.go index a0390780a..5507d7a78 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -28,6 +28,10 @@ import ( "strings" "time" + "github.com/gohugoio/hugo/common/constants" + + "github.com/gohugoio/hugo/common/loggers" + "github.com/gohugoio/hugo/resources" "github.com/gohugoio/hugo/identity" @@ -397,12 +401,34 @@ func newSite(cfg deps.DepsCfg) (*Site, error) { if cfg.Language == nil { cfg.Language = langs.NewDefaultLanguage(cfg.Cfg) } + if cfg.Logger == nil { + panic("logger must be set") + } + + ignoreErrors := cast.ToStringSlice(cfg.Language.Get("ignoreErrors")) + ignorableLogger := loggers.NewIgnorableLogger(cfg.Logger, ignoreErrors...) disabledKinds := make(map[string]bool) for _, disabled := range cast.ToStringSlice(cfg.Language.Get("disableKinds")) { disabledKinds[disabled] = true } + if disabledKinds["taxonomyTerm"] { + // Correct from the value it had before Hugo 0.73.0. + if disabledKinds[page.KindTaxonomy] { + disabledKinds[page.KindTerm] = true + } else { + disabledKinds[page.KindTaxonomy] = true + } + + delete(disabledKinds, "taxonomyTerm") + } else if disabledKinds[page.KindTaxonomy] && !disabledKinds[page.KindTerm] { + // This is a potentially ambigous situation. It may be correct. + ignorableLogger.Errorf(constants.ErrIDAmbigousDisableKindTaxonomy, `You have the value 'taxonomy' in the disabledKinds list. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term). +But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`) + + } + var ( mediaTypesConfig []map[string]interface{} outputFormatsConfig []map[string]interface{} @@ -444,7 +470,30 @@ func newSite(cfg deps.DepsCfg) (*Site, error) { siteOutputFormatsConfig = tmp } - outputFormats, err := createSiteOutputFormats(siteOutputFormatsConfig, cfg.Language, rssDisabled) + var siteOutputs map[string]interface{} + if cfg.Language.IsSet("outputs") { + siteOutputs = cfg.Language.GetStringMap("outputs") + + // Check and correct taxonomy kinds vs pre Hugo 0.73.0. + v1, hasTaxonomyTerm := siteOutputs["taxonomyterm"] + v2, hasTaxonomy := siteOutputs[page.KindTaxonomy] + _, hasTerm := siteOutputs[page.KindTerm] + if hasTaxonomy && hasTaxonomyTerm { + siteOutputs[page.KindTaxonomy] = v1 + siteOutputs[page.KindTerm] = v2 + delete(siteOutputs, "taxonomyTerm") + } else if hasTaxonomy && !hasTerm { + // This is a potentially ambigous situation. It may be correct. + ignorableLogger.Errorf(constants.ErrIDAmbigousOutputKindTaxonomy, `You have configured output formats for 'taxonomy' in your site configuration. In Hugo 0.73.0 we fixed these to be what most people expect (taxonomy and term). +But this also means that your site configuration may not do what you expect. If it is correct, you can suppress this message by following the instructions below.`) + } + if !hasTaxonomy && hasTaxonomyTerm { + siteOutputs[page.KindTaxonomy] = v1 + delete(siteOutputs, "taxonomyterm") + } + } + + outputFormats, err := createSiteOutputFormats(siteOutputFormatsConfig, siteOutputs, rssDisabled) if err != nil { return nil, err } @@ -1708,11 +1757,11 @@ func (s *Site) kindFromSections(sections []string) string { func (s *Site) kindFromSectionPath(sectionPath string) string { for _, plural := range s.siteCfg.taxonomiesConfig { if plural == sectionPath { - return page.KindTaxonomyTerm + return page.KindTaxonomy } if strings.HasPrefix(sectionPath, plural) { - return page.KindTaxonomy + return page.KindTerm } } diff --git a/hugolib/site_output.go b/hugolib/site_output.go index d064348a6..6a630f4ea 100644 --- a/hugolib/site_output.go +++ b/hugolib/site_output.go @@ -17,13 +17,12 @@ import ( "fmt" "strings" - "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/output" "github.com/gohugoio/hugo/resources/page" "github.com/spf13/cast" ) -func createDefaultOutputFormats(allFormats output.Formats, cfg config.Provider) map[string]output.Formats { +func createDefaultOutputFormats(allFormats output.Formats) map[string]output.Formats { rssOut, rssFound := allFormats.GetByName(output.RSSFormat.Name) htmlOut, _ := allFormats.GetByName(output.HTMLFormat.Name) robotsOut, _ := allFormats.GetByName(output.RobotsTxtFormat.Name) @@ -35,11 +34,11 @@ func createDefaultOutputFormats(allFormats output.Formats, cfg config.Provider) } m := map[string]output.Formats{ - page.KindPage: {htmlOut}, - page.KindHome: defaultListTypes, - page.KindSection: defaultListTypes, - page.KindTaxonomy: defaultListTypes, - page.KindTaxonomyTerm: defaultListTypes, + page.KindPage: {htmlOut}, + page.KindHome: defaultListTypes, + page.KindSection: defaultListTypes, + page.KindTerm: defaultListTypes, + page.KindTaxonomy: defaultListTypes, // Below are for consistency. They are currently not used during rendering. kindSitemap: {sitemapOut}, kindRobotsTXT: {robotsOut}, @@ -55,17 +54,15 @@ func createDefaultOutputFormats(allFormats output.Formats, cfg config.Provider) } -func createSiteOutputFormats(allFormats output.Formats, cfg config.Provider, rssDisabled bool) (map[string]output.Formats, error) { - defaultOutputFormats := createDefaultOutputFormats(allFormats, cfg) +func createSiteOutputFormats(allFormats output.Formats, outputs map[string]interface{}, rssDisabled bool) (map[string]output.Formats, error) { + defaultOutputFormats := createDefaultOutputFormats(allFormats) - if !cfg.IsSet("outputs") { + if outputs == nil { return defaultOutputFormats, nil } outFormats := make(map[string]output.Formats) - outputs := cfg.GetStringMap("outputs") - if len(outputs) == 0 { return outFormats, nil } diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index 232364577..c324be7dd 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -49,7 +49,7 @@ baseURL = "http://example.com/blog" paginate = 1 defaultContentLanguage = "en" -disableKinds = ["section", "taxonomy", "taxonomyTerm", "RSS", "sitemap", "robotsTXT", "404"] +disableKinds = ["section", "term", "taxonomy", "RSS", "sitemap", "robotsTXT", "404"] [Taxonomies] tag = "tags" @@ -226,7 +226,7 @@ baseURL = "http://example.com/blog" paginate = 1 defaultContentLanguage = "en" -disableKinds = ["page", "section", "taxonomy", "taxonomyTerm", "sitemap", "robotsTXT", "404"] +disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"] [outputFormats] [outputFormats.RSS] @@ -263,7 +263,7 @@ baseURL = "http://example.com/blog" paginate = 1 defaultContentLanguage = "en" -disableKinds = ["page", "section", "taxonomy", "taxonomyTerm", "sitemap", "robotsTXT", "404"] +disableKinds = ["page", "section", "term", "taxonomy", "sitemap", "robotsTXT", "404"] [mediaTypes] [mediaTypes."text/nodot"] @@ -341,14 +341,14 @@ func TestCreateSiteOutputFormats(t *testing.T) { cfg := viper.New() cfg.Set("outputs", outputsConfig) - outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg, false) + outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) c.Assert(err, qt.IsNil) c.Assert(outputs[page.KindSection], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.JSONFormat}) // Defaults + c.Assert(outputs[page.KindTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) - c.Assert(outputs[page.KindTaxonomyTerm], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) c.Assert(outputs[page.KindPage], deepEqualsOutputFormats, output.Formats{output.HTMLFormat}) // These aren't (currently) in use when rendering in Hugo, @@ -367,13 +367,15 @@ func TestCreateSiteOutputFormats(t *testing.T) { cfg := viper.New() outputsConfig := map[string]interface{}{ + // Note that we in Hugo 0.53.0 renamed this Kind to "taxonomy", + // but keep this test to test the legacy mapping. "taxonomyterm": []string{"JSON"}, } cfg.Set("outputs", outputsConfig) - outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg, false) + outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) c.Assert(err, qt.IsNil) - c.Assert(outputs[page.KindTaxonomyTerm], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) + c.Assert(outputs[page.KindTaxonomy], deepEqualsOutputFormats, output.Formats{output.JSONFormat}) }) @@ -389,7 +391,7 @@ func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) { cfg := viper.New() cfg.Set("outputs", outputsConfig) - _, err := createSiteOutputFormats(output.DefaultFormats, cfg, false) + _, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) c.Assert(err, qt.Not(qt.IsNil)) } @@ -403,7 +405,7 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) { cfg := viper.New() cfg.Set("outputs", outputsConfig) - outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg, false) + outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false) c.Assert(err, qt.IsNil) c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{output.HTMLFormat, output.RSSFormat}) } @@ -423,7 +425,7 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) { customHTML = output.Format{Name: "HTML", BaseName: "customHTML"} ) - outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg, false) + outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg.GetStringMap("outputs"), false) c.Assert(err, qt.IsNil) c.Assert(outputs[page.KindHome], deepEqualsOutputFormats, output.Formats{customHTML, customRSS}) } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 54c2fbe59..a2b3a0451 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -1066,7 +1066,7 @@ func TestClassCollectorStress(t *testing.T) { b := newTestSitesBuilder(t) b.WithConfigFile("toml", ` -disableKinds = ["home", "section", "taxonomy", "taxonomyTerm" ] +disableKinds = ["home", "section", "term", "taxonomy" ] [languages] [languages.en] diff --git a/hugolib/taxonomy_test.go b/hugolib/taxonomy_test.go index 64f560d25..4eeb92e06 100644 --- a/hugolib/taxonomy_test.go +++ b/hugolib/taxonomy_test.go @@ -167,16 +167,16 @@ permalinkeds: for taxonomy, count := range taxonomyTermPageCounts { msg := qt.Commentf(taxonomy) - term := s.getPage(page.KindTaxonomyTerm, taxonomy) + term := s.getPage(page.KindTaxonomy, taxonomy) b.Assert(term, qt.Not(qt.IsNil), msg) b.Assert(len(term.Pages()), qt.Equals, count, msg) for _, p := range term.Pages() { - b.Assert(p.Kind(), qt.Equals, page.KindTaxonomy) + b.Assert(p.Kind(), qt.Equals, page.KindTerm) } } - cat1 := s.getPage(page.KindTaxonomy, "categories", "cat1") + cat1 := s.getPage(page.KindTerm, "categories", "cat1") b.Assert(cat1, qt.Not(qt.IsNil)) if uglyURLs { b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1.html") @@ -184,8 +184,8 @@ permalinkeds: b.Assert(cat1.RelPermalink(), qt.Equals, "/blog/categories/cat1/") } - pl1 := s.getPage(page.KindTaxonomy, "permalinkeds", "pl1") - permalinkeds := s.getPage(page.KindTaxonomyTerm, "permalinkeds") + pl1 := s.getPage(page.KindTerm, "permalinkeds", "pl1") + permalinkeds := s.getPage(page.KindTaxonomy, "permalinkeds") b.Assert(pl1, qt.Not(qt.IsNil)) b.Assert(permalinkeds, qt.Not(qt.IsNil)) if uglyURLs { @@ -196,7 +196,7 @@ permalinkeds: b.Assert(permalinkeds.RelPermalink(), qt.Equals, "/blog/permalinkeds/") } - helloWorld := s.getPage(page.KindTaxonomy, "others", "hello-hugo-world") + helloWorld := s.getPage(page.KindTerm, "others", "hello-hugo-world") b.Assert(helloWorld, qt.Not(qt.IsNil)) b.Assert(helloWorld.Title(), qt.Equals, "Hello Hugo world") @@ -269,8 +269,8 @@ title: "This is S3s" return pages } - ta := filterbyKind(page.KindTaxonomy) - te := filterbyKind(page.KindTaxonomyTerm) + ta := filterbyKind(page.KindTerm) + te := filterbyKind(page.KindTaxonomy) b.Assert(len(te), qt.Equals, 4) b.Assert(len(ta), qt.Equals, 7) @@ -637,7 +637,7 @@ Cats Paginator {{ range $cats.Paginator.Pages }}{{ .RelPermalink }}|{{ end }}:EN b.Assert(funny, qt.Not(qt.IsNil)) b.Assert(cat.Parent().IsHome(), qt.Equals, true) - b.Assert(funny.Kind(), qt.Equals, "taxonomy") + b.Assert(funny.Kind(), qt.Equals, "term") b.Assert(funny.Parent(), qt.Equals, cat) b.AssertFileContent("public/index.html", ` @@ -697,13 +697,13 @@ abcdefgs: {{ template "print-page" $abcdefgs }}|IsAncestor: {{ $abcdefgs.IsAnces Page: /abcdefgh/|abcdefgh|section|Parent: /|CurrentSection: /abcdefgh/| Page: /abcdefgh/p1/|abcdefgh-p|page|Parent: /abcdefgh/|CurrentSection: /abcdefgh/| Page: /abcdefghijk/|abcdefghijk|page|Parent: /|CurrentSection: /| - Page: /abcdefghis/|Abcdefghis|taxonomyTerm|Parent: /|CurrentSection: /| - Page: /abcdefgs/|Abcdefgs|taxonomyTerm|Parent: /|CurrentSection: /| - Page: /abcdefs/|Abcdefs|taxonomyTerm|Parent: /|CurrentSection: /| - abc: /abcdefgs/abc/|abc|taxonomy|Parent: /abcdefgs/|CurrentSection: /abcdefgs/| - abcdefgs: /abcdefgs/|Abcdefgs|taxonomyTerm|Parent: /|CurrentSection: /| - abc: /abcdefgs/abc/|abc|taxonomy|Parent: /abcdefgs/|CurrentSection: /abcdefgs/|FirstSection: /|IsAncestor: false|IsDescendant: true - abcdefgs: /abcdefgs/|Abcdefgs|taxonomyTerm|Parent: /|CurrentSection: /|FirstSection: /|IsAncestor: true|IsDescendant: false + Page: /abcdefghis/|Abcdefghis|taxonomy|Parent: /|CurrentSection: /| + Page: /abcdefgs/|Abcdefgs|taxonomy|Parent: /|CurrentSection: /| + Page: /abcdefs/|Abcdefs|taxonomy|Parent: /|CurrentSection: /| + abc: /abcdefgs/abc/|abc|term|Parent: /abcdefgs/|CurrentSection: /abcdefgs/| + abcdefgs: /abcdefgs/|Abcdefgs|taxonomy|Parent: /|CurrentSection: /| + abc: /abcdefgs/abc/|abc|term|Parent: /abcdefgs/|CurrentSection: /abcdefgs/|FirstSection: /|IsAncestor: false|IsDescendant: true + abcdefgs: /abcdefgs/|Abcdefgs|taxonomy|Parent: /|CurrentSection: /|FirstSection: /|IsAncestor: true|IsDescendant: false `) } diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index eace35c97..c1ee27557 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -1070,3 +1070,18 @@ func captureStderr(f func() error) (string, error) { io.Copy(&buf, r) return buf.String(), err } + +func captureStdout(f func() error) (string, error) { + old := os.Stdout + r, w, _ := os.Pipe() + os.Stdout = w + + err := f() + + w.Close() + os.Stdout = old + + var buf bytes.Buffer + io.Copy(&buf, r) + return buf.String(), err +} |