mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 09:21:59 -05:00
Revert "hugolib: Restore taxonomy term path separation"
See #5571
This reverts commit 9ce0a1fb70
.
This commit is contained in:
parent
9e4f9e0bb6
commit
65fa069271
6 changed files with 14 additions and 88 deletions
|
@ -16,7 +16,6 @@ package hugolib
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -521,15 +520,6 @@ func (h *HugoSites) assignMissingTranslations() error {
|
||||||
func (h *HugoSites) createMissingPages() error {
|
func (h *HugoSites) createMissingPages() error {
|
||||||
var newPages Pages
|
var newPages Pages
|
||||||
|
|
||||||
singularPlural := func(p *Page) (string, string) {
|
|
||||||
slen := len(p.sections)
|
|
||||||
singular := p.sections[slen-1]
|
|
||||||
singular = p.s.PathSpec.MakePathSanitized(singular)
|
|
||||||
plural := path.Join((p.sections[:slen-1])...)
|
|
||||||
|
|
||||||
return singular, plural
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range h.Sites {
|
for _, s := range h.Sites {
|
||||||
if s.isEnabled(KindHome) {
|
if s.isEnabled(KindHome) {
|
||||||
// home pages
|
// home pages
|
||||||
|
@ -554,7 +544,6 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
if len(taxonomies) > 0 {
|
if len(taxonomies) > 0 {
|
||||||
taxonomyPages := s.findPagesByKind(KindTaxonomy)
|
taxonomyPages := s.findPagesByKind(KindTaxonomy)
|
||||||
taxonomyTermsPages := s.findPagesByKind(KindTaxonomyTerm)
|
taxonomyTermsPages := s.findPagesByKind(KindTaxonomyTerm)
|
||||||
|
|
||||||
for _, plural := range taxonomies {
|
for _, plural := range taxonomies {
|
||||||
if s.isEnabled(KindTaxonomyTerm) {
|
if s.isEnabled(KindTaxonomyTerm) {
|
||||||
foundTaxonomyTermsPage := false
|
foundTaxonomyTermsPage := false
|
||||||
|
@ -581,10 +570,11 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
key = s.PathSpec.MakeSegment(key)
|
key = s.PathSpec.MakeSegment(key)
|
||||||
}
|
}
|
||||||
for _, p := range taxonomyPages {
|
for _, p := range taxonomyPages {
|
||||||
|
// Some people may have /authors/MaxMustermann etc. as paths.
|
||||||
singularKey, pluralKey := singularPlural(p)
|
// p.sections contains the raw values from the file system.
|
||||||
|
// See https://github.com/gohugoio/hugo/issues/4238
|
||||||
if pluralKey == plural && singularKey == key {
|
singularKey := s.PathSpec.MakePathSanitized(p.sections[1])
|
||||||
|
if p.sections[0] == plural && singularKey == key {
|
||||||
foundTaxonomyPage = true
|
foundTaxonomyPage = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,8 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
|
||||||
// Check list pages
|
// Check list pages
|
||||||
b.AssertFileContent(pathMod("public/fr/sect/index.html"), "List", "Bonjour")
|
b.AssertFileContent(pathMod("public/fr/sect/index.html"), "List", "Bonjour")
|
||||||
b.AssertFileContent("public/en/sect/index.html", "List", "Hello")
|
b.AssertFileContent("public/en/sect/index.html", "List", "Hello")
|
||||||
b.AssertFileContent(pathMod("public/fr/plaques/frtag1/index.html"), "Taxonomy List", "Bonjour")
|
b.AssertFileContent(pathMod("public/fr/plaques/frtag1/index.html"), "List", "Bonjour")
|
||||||
b.AssertFileContent("public/en/tags/tag1/index.html", "Taxonomy List", "Hello")
|
b.AssertFileContent("public/en/tags/tag1/index.html", "List", "Hello")
|
||||||
|
|
||||||
// Check sitemaps
|
// Check sitemaps
|
||||||
// Sitemaps behaves different: In a multilanguage setup there will always be a index file and
|
// Sitemaps behaves different: In a multilanguage setup there will always be a index file and
|
||||||
|
|
|
@ -1774,8 +1774,8 @@ func (p *Page) prepareData(s *Site) error {
|
||||||
case KindHome:
|
case KindHome:
|
||||||
pages = s.RegularPages
|
pages = s.RegularPages
|
||||||
case KindTaxonomy:
|
case KindTaxonomy:
|
||||||
plural := path.Join(p.sections[:len(p.sections)-1]...)
|
plural := p.sections[0]
|
||||||
term := p.sections[len(p.sections)-1]
|
term := p.sections[1]
|
||||||
|
|
||||||
if s.Info.preserveTaxonomyNames {
|
if s.Info.preserveTaxonomyNames {
|
||||||
if v, ok := s.taxonomiesOrigKey[fmt.Sprintf("%s-%s", plural, term)]; ok {
|
if v, ok := s.taxonomiesOrigKey[fmt.Sprintf("%s-%s", plural, term)]; ok {
|
||||||
|
@ -1792,7 +1792,7 @@ func (p *Page) prepareData(s *Site) error {
|
||||||
p.data["Term"] = term
|
p.data["Term"] = term
|
||||||
pages = taxonomy.Pages()
|
pages = taxonomy.Pages()
|
||||||
case KindTaxonomyTerm:
|
case KindTaxonomyTerm:
|
||||||
plural := path.Join(p.sections...)
|
plural := p.sections[0]
|
||||||
singular := s.taxonomiesPluralSingular[plural]
|
singular := s.taxonomiesPluralSingular[plural]
|
||||||
|
|
||||||
p.data["Singular"] = singular
|
p.data["Singular"] = singular
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"mime"
|
"mime"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -1587,28 +1586,11 @@ func (s *Site) resetBuildState() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) singularPluralAll(sections []string) (string, string, string) {
|
|
||||||
slen := len(sections)
|
|
||||||
singular := sections[slen-1]
|
|
||||||
plural := path.Join((sections[:slen-1])...)
|
|
||||||
all := path.Join(sections...)
|
|
||||||
|
|
||||||
return singular, plural, all
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Site) kindFromSections(sections []string) string {
|
func (s *Site) kindFromSections(sections []string) string {
|
||||||
if len(sections) == 0 {
|
if len(sections) == 0 {
|
||||||
return KindSection
|
return KindSection
|
||||||
}
|
}
|
||||||
|
|
||||||
_, plural, all := s.singularPluralAll(sections)
|
|
||||||
|
|
||||||
if _, ok := s.Taxonomies[all]; ok {
|
|
||||||
return KindTaxonomyTerm
|
|
||||||
} else if _, ok := s.Taxonomies[plural]; ok {
|
|
||||||
return KindTaxonomy
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, isTaxonomy := s.Taxonomies[sections[0]]; isTaxonomy {
|
if _, isTaxonomy := s.Taxonomies[sections[0]]; isTaxonomy {
|
||||||
if len(sections) == 1 {
|
if len(sections) == 1 {
|
||||||
return KindTaxonomyTerm
|
return KindTaxonomyTerm
|
||||||
|
@ -1864,10 +1846,8 @@ func (s *Site) newHomePage() *Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) newTaxonomyPage(plural, key string) *Page {
|
func (s *Site) newTaxonomyPage(plural, key string) *Page {
|
||||||
sections := strings.Split(plural, "/")
|
|
||||||
sections = append(sections, key)
|
|
||||||
|
|
||||||
p := s.newNodePage(KindTaxonomy, sections...)
|
p := s.newNodePage(KindTaxonomy, plural, key)
|
||||||
|
|
||||||
if s.Info.preserveTaxonomyNames {
|
if s.Info.preserveTaxonomyNames {
|
||||||
p.title = key
|
p.title = key
|
||||||
|
@ -1891,7 +1871,7 @@ func (s *Site) newSectionPage(name string) *Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
func (s *Site) newTaxonomyTermsPage(plural string) *Page {
|
||||||
p := s.newNodePage(KindTaxonomyTerm, strings.Split(plural, "/")...)
|
p := s.newNodePage(KindTaxonomyTerm, plural)
|
||||||
p.title = s.titleFunc(plural)
|
p.title = s.titleFunc(plural)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,44 +243,3 @@ subcats:
|
||||||
th.assertFileContent(pathFunc("public/empties/index.html"), "Terms List", "Empties")
|
th.assertFileContent(pathFunc("public/empties/index.html"), "Terms List", "Empties")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gohugoio/hugo/issues/5513
|
|
||||||
func TestTaxonomyPathSeparation(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
config := `
|
|
||||||
baseURL = "https://example.com"
|
|
||||||
|
|
||||||
[taxonomies]
|
|
||||||
"news/tag" = "news/tags"
|
|
||||||
"news/category" = "news/categories"
|
|
||||||
`
|
|
||||||
|
|
||||||
pageContent := `
|
|
||||||
+++
|
|
||||||
title = "foo"
|
|
||||||
"news/categories" = ["a", "b", "c"]
|
|
||||||
+++
|
|
||||||
|
|
||||||
Content.
|
|
||||||
|
|
||||||
|
|
||||||
`
|
|
||||||
|
|
||||||
b := newTestSitesBuilder(t)
|
|
||||||
b.WithConfigFile("toml", config)
|
|
||||||
b.WithContent("page.md", pageContent)
|
|
||||||
b.WithContent("news/categories/b/_index.md", `
|
|
||||||
---
|
|
||||||
title: "This is B"
|
|
||||||
---
|
|
||||||
|
|
||||||
`)
|
|
||||||
|
|
||||||
b.CreateSites().Build(BuildCfg{})
|
|
||||||
|
|
||||||
b.AssertFileContent("public/news/categories/index.html", "Taxonomy Term Page 1|News/Categories|Hello|https://example.com/news/categories/|")
|
|
||||||
b.AssertFileContent("public/news/categories/a/index.html", "Taxonomy List Page 1|A|Hello|https://example.com/news/categories/a/|")
|
|
||||||
b.AssertFileContent("public/news/categories/b/index.html", "Taxonomy List Page 1|This is B|Hello|https://example.com/news/categories/b/|")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -420,15 +420,12 @@ date: "2018-02-28"
|
||||||
"content/sect/doc1.nn.md", contentTemplate,
|
"content/sect/doc1.nn.md", contentTemplate,
|
||||||
}
|
}
|
||||||
|
|
||||||
listTemplateCommon = "{{ $p := .Paginator }}{{ $p.PageNumber }}|{{ .Title }}|{{ i18n \"hello\" }}|{{ .Permalink }}|Pager: {{ template \"_internal/pagination.html\" . }}"
|
|
||||||
|
|
||||||
defaultTemplates = []string{
|
defaultTemplates = []string{
|
||||||
"_default/single.html", "Single: {{ .Title }}|{{ i18n \"hello\" }}|{{.Lang}}|{{ .Content }}",
|
"_default/single.html", "Single: {{ .Title }}|{{ i18n \"hello\" }}|{{.Lang}}|{{ .Content }}",
|
||||||
"_default/list.html", "List Page " + listTemplateCommon,
|
"_default/list.html", "{{ $p := .Paginator }}List Page {{ $p.PageNumber }}: {{ .Title }}|{{ i18n \"hello\" }}|{{ .Permalink }}|Pager: {{ template \"_internal/pagination.html\" . }}",
|
||||||
"index.html", "{{ $p := .Paginator }}Default Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}",
|
"index.html", "{{ $p := .Paginator }}Default Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}",
|
||||||
"index.fr.html", "{{ $p := .Paginator }}French Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}",
|
"index.fr.html", "{{ $p := .Paginator }}French Home Page {{ $p.PageNumber }}: {{ .Title }}|{{ .IsHome }}|{{ i18n \"hello\" }}|{{ .Permalink }}|{{ .Site.Data.hugo.slogan }}|String Resource: {{ ( \"Hugo Pipes\" | resources.FromString \"text/pipes.txt\").RelPermalink }}",
|
||||||
"_default/terms.html", "Taxonomy Term Page " + listTemplateCommon,
|
|
||||||
"_default/taxonomy.html", "Taxonomy List Page " + listTemplateCommon,
|
|
||||||
// Shortcodes
|
// Shortcodes
|
||||||
"shortcodes/shortcode.html", "Shortcode: {{ i18n \"hello\" }}",
|
"shortcodes/shortcode.html", "Shortcode: {{ i18n \"hello\" }}",
|
||||||
// A shortcode in multiple languages
|
// A shortcode in multiple languages
|
||||||
|
|
Loading…
Reference in a new issue