diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-07-05 19:32:57 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-07-05 20:35:20 +0200 |
commit | 12d3469dd1f5b5a2a459ccc33df6eb1b8eab6765 (patch) | |
tree | 3c16bf10e2b8c2966c07ab2a441d10a4c0c15f6a /helpers | |
parent | bf7ee8a91acf17613ffcd9c2f8c13abfa1ed0a11 (diff) | |
download | hugo-12d3469dd1f5b5a2a459ccc33df6eb1b8eab6765.tar.gz hugo-12d3469dd1f5b5a2a459ccc33df6eb1b8eab6765.zip |
Add titleCaseStyle none and firstupper
Fixes #11204
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/general.go | 6 | ||||
-rw-r--r-- | helpers/general_test.go | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/helpers/general.go b/helpers/general.go index d476b9125..f8f273397 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -205,6 +205,8 @@ func ReaderContains(r io.Reader, subslice []byte) bool { // - "Go" (strings.Title) // - "AP" (see https://www.apstylebook.com/) // - "Chicago" (see http://www.chicagomanualofstyle.org/home.html) +// - "FirstUpper" (only the first character is upper case) +// - "None" (no transformation) // // If an unknown or empty style is provided, AP style is what you get. func GetTitleFunc(style string) func(s string) string { @@ -214,6 +216,10 @@ func GetTitleFunc(style string) func(s string) string { case "chicago": tc := transform.NewTitleConverter(transform.ChicagoStyle) return tc.Title + case "none": + return func(s string) string { return s } + case "firstupper": + return FirstUpper default: tc := transform.NewTitleConverter(transform.APStyle) return tc.Title diff --git a/helpers/general_test.go b/helpers/general_test.go index 827411027..1463458fa 100644 --- a/helpers/general_test.go +++ b/helpers/general_test.go @@ -203,7 +203,7 @@ func TestReaderContains(t *testing.T) { } func TestGetTitleFunc(t *testing.T) { - title := "somewhere over the rainbow" + title := "somewhere over the Rainbow" c := qt.New(t) c.Assert(helpers.GetTitleFunc("go")(title), qt.Equals, "Somewhere Over The Rainbow") @@ -213,6 +213,8 @@ func TestGetTitleFunc(t *testing.T) { c.Assert(helpers.GetTitleFunc("ap")(title), qt.Equals, "Somewhere Over the Rainbow") c.Assert(helpers.GetTitleFunc("")(title), qt.Equals, "Somewhere Over the Rainbow") c.Assert(helpers.GetTitleFunc("unknown")(title), qt.Equals, "Somewhere Over the Rainbow") + c.Assert(helpers.GetTitleFunc("none")(title), qt.Equals, title) + c.Assert(helpers.GetTitleFunc("firstupper")(title), qt.Equals, "Somewhere over the Rainbow") } func BenchmarkReaderContains(b *testing.B) { |