summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-09-07 09:05:25 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-09-07 09:08:14 +0200
commite5d66074ce1ed4e0fe329e3fdef66f8b6fd5dc55 (patch)
treeff880dcb8d763708611ff6a306f4b5d13afa8aa0
parentd970327d7b994b495ef3bb468c3e0599b0deef5a (diff)
tpl/strings: Add strings.FirstUpper
Fixes #5174
-rw-r--r--docs/content/en/content-management/taxonomies.md5
-rw-r--r--tpl/strings/init.go7
-rw-r--r--tpl/strings/strings.go10
3 files changed, 19 insertions, 3 deletions
diff --git a/docs/content/en/content-management/taxonomies.md b/docs/content/en/content-management/taxonomies.md
index 8260cfc1f..c06b2385b 100644
--- a/docs/content/en/content-management/taxonomies.md
+++ b/docs/content/en/content-management/taxonomies.md
@@ -150,9 +150,9 @@ Much like regular pages, taxonomy list [permalinks](/content-management/urls/) a
{{% /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.
+Before 0.49, Hugo would make the first character upper case for 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][].
+If you actually need to title-ize these values, you can do so using the `strings.FirstUpper` template function.
{{% /warning %}}
## Add Taxonomies to Content
@@ -211,7 +211,6 @@ If you need to add custom metadata to your taxonomy terms, you will need to crea
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/
diff --git a/tpl/strings/init.go b/tpl/strings/init.go
index 8ff4cf98f..7e638e6fc 100644
--- a/tpl/strings/init.go
+++ b/tpl/strings/init.go
@@ -155,6 +155,13 @@ func init() {
},
)
+ ns.AddMethodMapping(ctx.FirstUpper,
+ nil,
+ [][2]string{
+ {`{{ "hugo rocks!" | strings.FirstUpper }}`, `Hugo rocks!`},
+ },
+ )
+
ns.AddMethodMapping(ctx.Truncate,
[]string{"truncate"},
[][2]string{
diff --git a/tpl/strings/strings.go b/tpl/strings/strings.go
index 1864bb9e0..9b8409ed6 100644
--- a/tpl/strings/strings.go
+++ b/tpl/strings/strings.go
@@ -325,6 +325,16 @@ func (ns *Namespace) Title(s interface{}) (string, error) {
return ns.titleFunc(ss), nil
}
+// FirstUpper returns a string with the first character as upper case.
+func (ns *Namespace) FirstUpper(s interface{}) (string, error) {
+ ss, err := cast.ToStringE(s)
+ if err != nil {
+ return "", err
+ }
+
+ return helpers.FirstUpper(ss), nil
+}
+
// ToLower returns a copy of the input s with all Unicode letters mapped to their
// lower case.
func (ns *Namespace) ToLower(s interface{}) (string, error) {