shithub: hugo

Download patch

ref: be3ae3ec92da972a55112af39ce2e1c45121b9a5
parent: 2cf8fe2ea218d37776af72893691e772737750e3
author: Thomas Jost <[email protected]>
date: Thu Sep 6 11:45:29 EDT 2018

hugolib: Do not FirstUpper taxonomy titles

Doing so was probably a mistake. This may be a breaking change for some people,
but it's easy to restore the previous behaviour in the layouts.

Fixes #5172

--- a/docs/content/en/content-management/taxonomies.md
+++ b/docs/content/en/content-management/taxonomies.md
@@ -139,7 +139,7 @@
 
 By default, taxonomy names are normalized.
 
-Therefore, if you want to have a taxonomy term with special characters such as `Gérard Depardieu` instead of `Gerard Depardieu`, set the value for `preserveTaxonomyNames` to `true` in your [site config][config]. Hugo will then preserve special characters in taxonomy values but will still title-ize the values for titles and normalize them in URLs.
+Therefore, if you want to have a taxonomy term with special characters such as `Gérard Depardieu` instead of `Gerard Depardieu`, set the value for `preserveTaxonomyNames` to `true` in your [site config][config]. Hugo will then preserve special characters in taxonomy values but will still normalize them in URLs.
 
 Note that if you use `preserveTaxonomyNames` and intend to manually construct URLs to the archive pages, you will need to pass the taxonomy values through the [`urlize` template function][].
 
@@ -149,6 +149,12 @@
 Much like regular pages, taxonomy list [permalinks](/content-management/urls/) are configurable, but taxonomy term page permalinks are not.
 {{% /note %}}
 
+{{% warning "`preserveTaxonomyNames` behaviour change" %}}
+Before 0.49, Hugo would title-ize the taxonomy values for titles even if `preserveTaxonomyNames` was active. This no longer the case, which (for instance) makes it possible to have fully lower-case values.
+
+If you actually need to title-ize these values, you can do so using the [`title` template function][].
+{{% /warning %}}
+
 ## Add Taxonomies to Content
 
 Once a taxonomy is defined at the site level, any piece of content can be assigned to it, regardless of [content type][] or [content section][].
@@ -205,6 +211,7 @@
 
 You can later use your custom metadata as shown in the [Taxonomy Terms Templates documentation](/templates/taxonomy-templates/#displaying-custom-metadata-in-taxonomy-terms-templates).
 
+[`title` template function]: /functions/title/
 [`urlize` template function]: /functions/urlize/
 [content section]: /content-management/sections/
 [content type]: /content-management/types/
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1830,10 +1830,7 @@
 	p := s.newNodePage(KindTaxonomy, plural, key)
 
 	if s.Info.preserveTaxonomyNames {
-		// Keep (mostly) as is in the title
-		// We make the first character upper case, mostly because
-		// it is easier to reason about in the tests.
-		p.title = helpers.FirstUpper(key)
+		p.title = key
 	} else {
 		p.title = strings.Replace(s.titleFunc(key), "-", " ", -1)
 	}
--- a/hugolib/taxonomy_test.go
+++ b/hugolib/taxonomy_test.go
@@ -129,27 +129,38 @@
 	}
 
 	// 1.
-	th.assertFileContent(pathFunc("public/categories/cat1/index.html"), "List", "Cat1")
 	if preserveTaxonomyNames {
-		// As of this writing, term titles are given a first upper.
-		// See hugolib.Site.newTaxonomyPage().
-		th.assertFileContent(pathFunc("public/categories/cat-dog/index.html"), "List", "CAt/dOg")
+		th.assertFileContent(pathFunc("public/categories/cat1/index.html"), "List", "cat1")
+		th.assertFileContent(pathFunc("public/categories/cat-dog/index.html"), "List", "cAt/dOg")
 	} else {
+		th.assertFileContent(pathFunc("public/categories/cat1/index.html"), "List", "Cat1")
 		th.assertFileContent(pathFunc("public/categories/cat-dog/index.html"), "List", "Cat/Dog")
 	}
 	th.assertFileContent(pathFunc("public/categories/index.html"), "Terms List", "Category Terms")
 
 	// 2.
-	th.assertFileContent(pathFunc("public/tags/tag2/index.html"), "List", "Tag2")
+	if preserveTaxonomyNames {
+		th.assertFileContent(pathFunc("public/tags/tag2/index.html"), "List", "tag2")
+	} else {
+		th.assertFileContent(pathFunc("public/tags/tag2/index.html"), "List", "Tag2")
+	}
 	th.assertFileContent(pathFunc("public/tags/tag1/index.html"), "List", "Tag1")
 	th.assertFileContent(pathFunc("public/tags/index.html"), "Terms List", "Tags")
 
 	// 3.
-	th.assertFileContent(pathFunc("public/others/o1/index.html"), "List", "O1")
+	if preserveTaxonomyNames {
+		th.assertFileContent(pathFunc("public/others/o1/index.html"), "List", "o1")
+	} else {
+		th.assertFileContent(pathFunc("public/others/o1/index.html"), "List", "O1")
+	}
 	th.assertFileContent(pathFunc("public/others/index.html"), "Terms List", "Others")
 
 	// 4.
-	th.assertFileContent(pathFunc("public/perma/pl1/index.html"), "List", "Pl1")
+	if preserveTaxonomyNames {
+		th.assertFileContent(pathFunc("public/perma/pl1/index.html"), "List", "pl1")
+	} else {
+		th.assertFileContent(pathFunc("public/perma/pl1/index.html"), "List", "Pl1")
+	}
 	// This looks kind of funky, but the taxonomy terms do not have a permalinks definition,
 	// for good reasons.
 	th.assertFileContent(pathFunc("public/permalinkeds/index.html"), "Terms List", "Permalinkeds")