mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-23 11:03:47 +00:00
parent
862f09babe
commit
bcb3ef7413
4 changed files with 36 additions and 4 deletions
|
@ -225,6 +225,9 @@ func (h *HugoSites) createMissingPages() error {
|
||||||
foundTaxonomyPage := false
|
foundTaxonomyPage := false
|
||||||
foundTaxonomyTermsPage := false
|
foundTaxonomyTermsPage := false
|
||||||
for key := range tax {
|
for key := range tax {
|
||||||
|
if s.Info.preserveTaxonomyNames {
|
||||||
|
key = s.Info.pathSpec.MakePathSanitized(key)
|
||||||
|
}
|
||||||
for _, p := range taxonomyPages {
|
for _, p := range taxonomyPages {
|
||||||
if p.sections[0] == plural && p.sections[1] == key {
|
if p.sections[0] == plural && p.sections[1] == key {
|
||||||
foundTaxonomyPage = true
|
foundTaxonomyPage = true
|
||||||
|
|
|
@ -33,12 +33,14 @@ import (
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func TestNodesAsPage(t *testing.T) {
|
func TestNodesAsPage(t *testing.T) {
|
||||||
for _, ugly := range []bool{false, true} {
|
for _, preserveTaxonomyNames := range []bool{false, true} {
|
||||||
doTestNodeAsPage(t, ugly)
|
for _, ugly := range []bool{true, false} {
|
||||||
|
doTestNodeAsPage(t, ugly, preserveTaxonomyNames)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestNodeAsPage(t *testing.T, ugly bool) {
|
func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
|
||||||
//jww.SetStdoutThreshold(jww.LevelDebug)
|
//jww.SetStdoutThreshold(jww.LevelDebug)
|
||||||
jww.SetStdoutThreshold(jww.LevelFatal)
|
jww.SetStdoutThreshold(jww.LevelFatal)
|
||||||
|
|
||||||
|
@ -55,6 +57,7 @@ func doTestNodeAsPage(t *testing.T, ugly bool) {
|
||||||
testCommonResetState()
|
testCommonResetState()
|
||||||
|
|
||||||
viper.Set("uglyURLs", ugly)
|
viper.Set("uglyURLs", ugly)
|
||||||
|
viper.Set("preserveTaxonomyNames", preserveTaxonomyNames)
|
||||||
|
|
||||||
writeLayoutsForNodeAsPageTests(t)
|
writeLayoutsForNodeAsPageTests(t)
|
||||||
writeNodePagesForNodeAsPageTests("", t)
|
writeNodePagesForNodeAsPageTests("", t)
|
||||||
|
@ -86,6 +89,7 @@ func doTestNodeAsPage(t *testing.T, ugly bool) {
|
||||||
|
|
||||||
h := s.owner
|
h := s.owner
|
||||||
nodes := h.findAllPagesByKindNotIn(KindPage)
|
nodes := h.findAllPagesByKindNotIn(KindPage)
|
||||||
|
|
||||||
require.Len(t, nodes, 6)
|
require.Len(t, nodes, 6)
|
||||||
|
|
||||||
home := nodes[5] // oldest
|
home := nodes[5] // oldest
|
||||||
|
@ -139,6 +143,10 @@ func doTestNodeAsPage(t *testing.T, ugly bool) {
|
||||||
"Lastmod: 2009-01-09",
|
"Lastmod: 2009-01-09",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
web := s.getPage(KindTaxonomy, "categories", "web")
|
||||||
|
require.NotNil(t, web)
|
||||||
|
require.Len(t, web.Data["Pages"].(Pages), 4)
|
||||||
|
|
||||||
assertFileContent(t, expectedFilePath(ugly, "public", "categories", "web"), false,
|
assertFileContent(t, expectedFilePath(ugly, "public", "categories", "web"), false,
|
||||||
"Taxonomy Title: Taxonomy Web",
|
"Taxonomy Title: Taxonomy Web",
|
||||||
"Taxonomy Web <strong>Content!</strong>",
|
"Taxonomy Web <strong>Content!</strong>",
|
||||||
|
@ -728,7 +736,7 @@ Lastmod: {{ .Lastmod.Format "2006-01-02" }}
|
||||||
Taxonomy Terms Title: {{ .Title }}
|
Taxonomy Terms Title: {{ .Title }}
|
||||||
Taxonomy Terms Content: {{ .Content }}
|
Taxonomy Terms Content: {{ .Content }}
|
||||||
{{ range $key, $value := .Data.Terms }}
|
{{ range $key, $value := .Data.Terms }}
|
||||||
k/v: {{ $key }} / {{ printf "%s" $value }}
|
k/v: {{ $key | lower }} / {{ printf "%s" $value }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ with .Site.Menus.mymenu }}
|
{{ with .Site.Menus.mymenu }}
|
||||||
{{ range . }}
|
{{ range . }}
|
||||||
|
|
|
@ -1494,6 +1494,12 @@ func (p *Page) prepareData(s *Site) error {
|
||||||
plural := p.sections[0]
|
plural := p.sections[0]
|
||||||
term := p.sections[1]
|
term := p.sections[1]
|
||||||
|
|
||||||
|
if s.Info.preserveTaxonomyNames {
|
||||||
|
if v, ok := s.taxonomiesOrigKey[fmt.Sprintf("%s-%s", plural, term)]; ok {
|
||||||
|
term = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
singular := s.taxonomiesPluralSingular[plural]
|
singular := s.taxonomiesPluralSingular[plural]
|
||||||
taxonomy := s.Taxonomies[plural].Get(term)
|
taxonomy := s.Taxonomies[plural].Get(term)
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,11 @@ type Site struct {
|
||||||
// to get the singular form from that value.
|
// to get the singular form from that value.
|
||||||
taxonomiesPluralSingular map[string]string
|
taxonomiesPluralSingular map[string]string
|
||||||
|
|
||||||
|
// This is temporary, see https://github.com/spf13/hugo/issues/2835
|
||||||
|
// Maps "actors-gerard-depardieu" to "Gérard Depardieu" when preserveTaxonomyNames
|
||||||
|
// is set.
|
||||||
|
taxonomiesOrigKey map[string]string
|
||||||
|
|
||||||
Source source.Input
|
Source source.Input
|
||||||
Sections Taxonomy
|
Sections Taxonomy
|
||||||
Info SiteInfo
|
Info SiteInfo
|
||||||
|
@ -1477,8 +1482,10 @@ func (s *Site) assembleMenus() {
|
||||||
func (s *Site) assembleTaxonomies() {
|
func (s *Site) assembleTaxonomies() {
|
||||||
s.Taxonomies = make(TaxonomyList)
|
s.Taxonomies = make(TaxonomyList)
|
||||||
s.taxonomiesPluralSingular = make(map[string]string)
|
s.taxonomiesPluralSingular = make(map[string]string)
|
||||||
|
s.taxonomiesOrigKey = make(map[string]string)
|
||||||
|
|
||||||
taxonomies := s.Language.GetStringMapString("taxonomies")
|
taxonomies := s.Language.GetStringMapString("taxonomies")
|
||||||
|
|
||||||
jww.INFO.Printf("found taxonomies: %#v\n", taxonomies)
|
jww.INFO.Printf("found taxonomies: %#v\n", taxonomies)
|
||||||
|
|
||||||
for singular, plural := range taxonomies {
|
for singular, plural := range taxonomies {
|
||||||
|
@ -1496,10 +1503,18 @@ func (s *Site) assembleTaxonomies() {
|
||||||
for _, idx := range v {
|
for _, idx := range v {
|
||||||
x := WeightedPage{weight.(int), p}
|
x := WeightedPage{weight.(int), p}
|
||||||
s.Taxonomies[plural].add(idx, x, s.Info.preserveTaxonomyNames)
|
s.Taxonomies[plural].add(idx, x, s.Info.preserveTaxonomyNames)
|
||||||
|
if s.Info.preserveTaxonomyNames {
|
||||||
|
// Need to track the original
|
||||||
|
s.taxonomiesOrigKey[fmt.Sprintf("%s-%s", plural, kp(idx))] = idx
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if v, ok := vals.(string); ok {
|
} else if v, ok := vals.(string); ok {
|
||||||
x := WeightedPage{weight.(int), p}
|
x := WeightedPage{weight.(int), p}
|
||||||
s.Taxonomies[plural].add(v, x, s.Info.preserveTaxonomyNames)
|
s.Taxonomies[plural].add(v, x, s.Info.preserveTaxonomyNames)
|
||||||
|
if s.Info.preserveTaxonomyNames {
|
||||||
|
// Need to track the original
|
||||||
|
s.taxonomiesOrigKey[fmt.Sprintf("%s-%s", plural, kp(v))] = v
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.Path())
|
jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.Path())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue