mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
Add PreserveTaxonomyNames flag
Before this commit, taxonomy names were hyphenated, lower-cased and normalized -- then fixed and titleized on the archive page. So what you entered in the front matter isn't necessarily what you got in the final site. To preserve backwards compability, `PreserveTaxonomyNames` is default `false`. Setting it to `true` will preserve what you type (the first characters is made toupper for titles), but normalized in URLs. This also means that, if you manually construct URLs to the archive pages, you will have to pass the Taxonomy names through the `urlize` func. Fixes #1180
This commit is contained in:
@@ -93,27 +93,28 @@ type targetList struct {
|
||||
}
|
||||
|
||||
type SiteInfo struct {
|
||||
BaseURL template.URL
|
||||
Taxonomies TaxonomyList
|
||||
Authors AuthorList
|
||||
Social SiteSocial
|
||||
Sections Taxonomy
|
||||
Pages *Pages
|
||||
Files []*source.File
|
||||
Menus *Menus
|
||||
Hugo *HugoInfo
|
||||
Title string
|
||||
Author map[string]interface{}
|
||||
LanguageCode string
|
||||
DisqusShortname string
|
||||
Copyright string
|
||||
LastChange time.Time
|
||||
Permalinks PermalinkOverrides
|
||||
Params map[string]interface{}
|
||||
BuildDrafts bool
|
||||
canonifyURLs bool
|
||||
paginationPageCount uint64
|
||||
Data *map[string]interface{}
|
||||
BaseURL template.URL
|
||||
Taxonomies TaxonomyList
|
||||
Authors AuthorList
|
||||
Social SiteSocial
|
||||
Sections Taxonomy
|
||||
Pages *Pages
|
||||
Files []*source.File
|
||||
Menus *Menus
|
||||
Hugo *HugoInfo
|
||||
Title string
|
||||
Author map[string]interface{}
|
||||
LanguageCode string
|
||||
DisqusShortname string
|
||||
Copyright string
|
||||
LastChange time.Time
|
||||
Permalinks PermalinkOverrides
|
||||
Params map[string]interface{}
|
||||
BuildDrafts bool
|
||||
canonifyURLs bool
|
||||
preserveTaxonomyNames bool
|
||||
paginationPageCount uint64
|
||||
Data *map[string]interface{}
|
||||
}
|
||||
|
||||
// SiteSocial is a place to put social details on a site level. These are the
|
||||
@@ -465,19 +466,20 @@ func (s *Site) initializeSiteInfo() {
|
||||
}
|
||||
|
||||
s.Info = SiteInfo{
|
||||
BaseURL: template.URL(helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL"))),
|
||||
Title: viper.GetString("Title"),
|
||||
Author: viper.GetStringMap("author"),
|
||||
LanguageCode: viper.GetString("languagecode"),
|
||||
Copyright: viper.GetString("copyright"),
|
||||
DisqusShortname: viper.GetString("DisqusShortname"),
|
||||
BuildDrafts: viper.GetBool("BuildDrafts"),
|
||||
canonifyURLs: viper.GetBool("CanonifyURLs"),
|
||||
Pages: &s.Pages,
|
||||
Menus: &s.Menus,
|
||||
Params: params,
|
||||
Permalinks: permalinks,
|
||||
Data: &s.Data,
|
||||
BaseURL: template.URL(helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL"))),
|
||||
Title: viper.GetString("Title"),
|
||||
Author: viper.GetStringMap("author"),
|
||||
LanguageCode: viper.GetString("languagecode"),
|
||||
Copyright: viper.GetString("copyright"),
|
||||
DisqusShortname: viper.GetString("DisqusShortname"),
|
||||
BuildDrafts: viper.GetBool("BuildDrafts"),
|
||||
canonifyURLs: viper.GetBool("CanonifyURLs"),
|
||||
preserveTaxonomyNames: viper.GetBool("PreserveTaxonomyNames"),
|
||||
Pages: &s.Pages,
|
||||
Menus: &s.Menus,
|
||||
Params: params,
|
||||
Permalinks: permalinks,
|
||||
Data: &s.Data,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -833,21 +835,20 @@ func (s *Site) assembleTaxonomies() {
|
||||
for _, plural := range taxonomies {
|
||||
s.Taxonomies[plural] = make(Taxonomy)
|
||||
for _, p := range s.Pages {
|
||||
vals := p.GetParam(plural)
|
||||
vals := p.getParam(plural, !s.Info.preserveTaxonomyNames)
|
||||
weight := p.GetParam(plural + "_weight")
|
||||
if weight == nil {
|
||||
weight = 0
|
||||
}
|
||||
|
||||
if vals != nil {
|
||||
if v, ok := vals.([]string); ok {
|
||||
for _, idx := range v {
|
||||
x := WeightedPage{weight.(int), p}
|
||||
s.Taxonomies[plural].Add(idx, x)
|
||||
s.Taxonomies[plural].Add(idx, x, s.Info.preserveTaxonomyNames)
|
||||
}
|
||||
} else if v, ok := vals.(string); ok {
|
||||
x := WeightedPage{weight.(int), p}
|
||||
s.Taxonomies[plural].Add(v, x)
|
||||
s.Taxonomies[plural].Add(v, x, s.Info.preserveTaxonomyNames)
|
||||
} else {
|
||||
jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.Path())
|
||||
}
|
||||
@@ -864,7 +865,7 @@ func (s *Site) assembleTaxonomies() {
|
||||
|
||||
func (s *Site) assembleSections() {
|
||||
for i, p := range s.Pages {
|
||||
s.Sections.Add(p.Section(), WeightedPage{s.Pages[i].Weight, s.Pages[i]})
|
||||
s.Sections.Add(p.Section(), WeightedPage{s.Pages[i].Weight, s.Pages[i]}, s.Info.preserveTaxonomyNames)
|
||||
}
|
||||
|
||||
for k := range s.Sections {
|
||||
@@ -1058,9 +1059,16 @@ func (s *Site) RenderTaxonomiesLists() error {
|
||||
}
|
||||
|
||||
func (s *Site) newTaxonomyNode(t taxRenderInfo) (*Node, string) {
|
||||
base := t.plural + "/" + t.key
|
||||
key := t.key
|
||||
n := s.NewNode()
|
||||
n.Title = strings.Replace(strings.Title(t.key), "-", " ", -1)
|
||||
if s.Info.preserveTaxonomyNames {
|
||||
key = helpers.MakePathToLower(key)
|
||||
// keep as is, just make sure the first char is upper
|
||||
n.Title = helpers.FirstUpper(t.key)
|
||||
} else {
|
||||
n.Title = strings.Replace(strings.Title(t.key), "-", " ", -1)
|
||||
}
|
||||
base := t.plural + "/" + key
|
||||
s.setURLs(n, base)
|
||||
if len(t.pages) > 0 {
|
||||
n.Date = t.pages[0].Page.Date
|
||||
@@ -1179,16 +1187,19 @@ func (s *Site) newSectionListNode(sectionName, section string, data WeightedPage
|
||||
// RenderSectionLists renders a page for each section
|
||||
func (s *Site) RenderSectionLists() error {
|
||||
for section, data := range s.Sections {
|
||||
|
||||
// section keys are lower case
|
||||
// section keys can be lower case (depending on site.pathifyTaxonomyKeys)
|
||||
// extract the original casing from the first page to get sensible titles.
|
||||
sectionName := section
|
||||
if len(data) > 0 {
|
||||
if !s.Info.preserveTaxonomyNames && len(data) > 0 {
|
||||
sectionName = data[0].Page.Section()
|
||||
}
|
||||
layouts := s.appendThemeTemplates(
|
||||
[]string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"})
|
||||
|
||||
if s.Info.preserveTaxonomyNames {
|
||||
section = helpers.MakePathToLower(section)
|
||||
}
|
||||
|
||||
n := s.newSectionListNode(sectionName, section, data)
|
||||
if err := s.renderAndWritePage(fmt.Sprintf("section %s", section), section, n, s.appendThemeTemplates(layouts)...); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user