mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 02:42:08 -05:00
hugolib: Fix issue with taxonomies when only some have content page
Fixes #2992
This commit is contained in:
parent
07ab7ae3d2
commit
4493e8ed9f
2 changed files with 83 additions and 1 deletions
|
@ -321,9 +321,9 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
taxonomyTermsPages := s.findPagesByKind(KindTaxonomyTerm)
|
taxonomyTermsPages := s.findPagesByKind(KindTaxonomyTerm)
|
||||||
for _, plural := range taxonomies {
|
for _, plural := range taxonomies {
|
||||||
tax := s.Taxonomies[plural]
|
tax := s.Taxonomies[plural]
|
||||||
foundTaxonomyPage := false
|
|
||||||
foundTaxonomyTermsPage := false
|
foundTaxonomyTermsPage := false
|
||||||
for key := range tax {
|
for key := range tax {
|
||||||
|
foundTaxonomyPage := false
|
||||||
if s.Info.preserveTaxonomyNames {
|
if s.Info.preserveTaxonomyNames {
|
||||||
key = s.PathSpec.MakePathSanitized(key)
|
key = s.PathSpec.MakePathSanitized(key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,16 @@
|
||||||
package hugolib
|
package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spf13/afero"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/spf13/hugo/deps"
|
"github.com/spf13/hugo/deps"
|
||||||
|
"github.com/spf13/hugo/hugofs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestByCountOrderOfTaxonomies(t *testing.T) {
|
func TestByCountOrderOfTaxonomies(t *testing.T) {
|
||||||
|
@ -45,3 +50,80 @@ func TestByCountOrderOfTaxonomies(t *testing.T) {
|
||||||
t.Fatalf("ordered taxonomies do not match [a, b, c]. Got: %s", st)
|
t.Fatalf("ordered taxonomies do not match [a, b, c]. Got: %s", st)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #2992
|
||||||
|
func TestTaxonomiesWithAndWithoutContentFile(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
siteConfig := `
|
||||||
|
baseURL = "http://example.com/blog"
|
||||||
|
|
||||||
|
paginate = 1
|
||||||
|
defaultContentLanguage = "en"
|
||||||
|
|
||||||
|
[Taxonomies]
|
||||||
|
tag = "tags"
|
||||||
|
category = "categories"
|
||||||
|
other = "others"
|
||||||
|
`
|
||||||
|
|
||||||
|
pageTemplate := `---
|
||||||
|
title: "%s"
|
||||||
|
tags:
|
||||||
|
%s
|
||||||
|
categories:
|
||||||
|
%s
|
||||||
|
others:
|
||||||
|
%s
|
||||||
|
---
|
||||||
|
# Doc
|
||||||
|
`
|
||||||
|
|
||||||
|
mf := afero.NewMemMapFs()
|
||||||
|
|
||||||
|
writeToFs(t, mf, "config.toml", siteConfig)
|
||||||
|
|
||||||
|
cfg, err := LoadConfig(mf, "", "config.toml")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
fs := hugofs.NewFrom(mf, cfg)
|
||||||
|
th := testHelper{cfg, fs, t}
|
||||||
|
|
||||||
|
writeSource(t, fs, "layouts/_default/single.html", "Single|{{ .Title }}|{{ .Content }}")
|
||||||
|
writeSource(t, fs, "layouts/_default/list.html", "List|{{ .Title }}|{{ .Content }}")
|
||||||
|
writeSource(t, fs, "layouts/_default/terms.html", "Terms List|{{ .Title }}|{{ .Content }}")
|
||||||
|
|
||||||
|
writeSource(t, fs, "content/p1.md", fmt.Sprintf(pageTemplate, "t1/c1", "- tag1", "- cat1", "- o1"))
|
||||||
|
writeSource(t, fs, "content/p2.md", fmt.Sprintf(pageTemplate, "t2/c1", "- tag2", "- cat1", "- o1"))
|
||||||
|
|
||||||
|
writeNewContentFile(t, fs, "Category Terms", "2017-01-01", "content/categories/_index.md", 10)
|
||||||
|
writeNewContentFile(t, fs, "Tag1 List", "2017-01-01", "content/tags/tag1/_index.md", 10)
|
||||||
|
|
||||||
|
h, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg})
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, h.Sites, 1)
|
||||||
|
|
||||||
|
err = h.Build(BuildCfg{})
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// 1.
|
||||||
|
th.assertFileContent("public/categories/cat1/index.html", "List", "Cat1")
|
||||||
|
th.assertFileContent("public/categories/index.html", "Terms List", "Category Terms")
|
||||||
|
|
||||||
|
// 2.
|
||||||
|
th.assertFileContent("public/tags/tag2/index.html", "List", "Tag2")
|
||||||
|
th.assertFileContent("public/tags/tag1/index.html", "List", "Tag1")
|
||||||
|
th.assertFileContent("public/tags/index.html", "Terms List", "Tags")
|
||||||
|
|
||||||
|
// 3.
|
||||||
|
th.assertFileContent("public/others/o1/index.html", "List", "O1")
|
||||||
|
th.assertFileContent("public/others/index.html", "Terms List", "Others")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue