preserve alias case while lowercasing taxonomy
authorJoel Scoble <joel.scoble@outlook.com>
Thu, 21 Aug 2014 23:01:34 +0000 (18:01 -0500)
committerspf13 <steve.francia@gmail.com>
Mon, 25 Aug 2014 14:16:59 +0000 (10:16 -0400)
helpers/helpers_test.go
helpers/path.go
hugolib/taxonomy.go

index 71e894766d1fd1ee545e4e14cc7108f77637ffa1..822783025330e327d1409d2edd2770b075b49642 100644 (file)
@@ -36,6 +36,28 @@ func TestUgly(t *testing.T) {
 }
 
 func TestMakePath(t *testing.T) {
+       tests := []struct {
+               input    string
+               expected string
+       }{
+               {"  Foo bar  ", "Foo-bar"},
+               {"Foo.Bar/foo_Bar-Foo", "Foo.Bar/foo_Bar-Foo"},
+               {"fOO,bar:foo%bAR", "fOObarfoobAR"},
+               {"FOo/BaR.html", "FOo/BaR.html"},
+               {"трям/трям", "трям/трям"},
+               {"은행","은행"},
+               {"Банковский кассир","Банковский-кассир"},
+       }
+
+       for _, test := range tests {
+               output := MakePath(test.input)
+               if output != test.expected {
+                       t.Errorf("Expected %#v, got %#v\n", test.expected, output)
+               }
+       }
+}
+
+func TestMakeToLower(t *testing.T) {
        tests := []struct {
                input    string
                expected string
@@ -45,6 +67,7 @@ func TestMakePath(t *testing.T) {
                {"foo,bar:foo%bar", "foobarfoobar"},
                {"foo/bar.html", "foo/bar.html"},
                {"трям/трям", "трям/трям"},
+               {"은행","은행"},
        }
 
        for _, test := range tests {
index 0cd56e0d991ee58e0f4f9f65fc039dc93c1515a1..2f63c718cd134fc9bda7b43d70ba16fbda279dfc 100644 (file)
@@ -29,9 +29,18 @@ import (
 var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]")
 
 // Take a string with any characters and replace it so the string could be used in a path.
-// E.g. Social Media -> social-media
+// MakePath creates a Unicode sanitized string, with the spaces replaced, whilst
+// preserving the original casing of the string.
+// E.g. Social Media -> Social-Media
 func MakePath(s string) string {
-       return UnicodeSanitize(strings.ToLower(strings.Replace(strings.TrimSpace(s), " ", "-", -1)))
+       return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1))
+}
+
+// MakePathToLowerr creates a Unicode santized string, with the spaces replaced,
+// and transformed to lower case.
+// E.g. Social Media -> social-media
+func MakePathToLower(s string) string {
+        return UnicodeSanitize(strings.ToLower(strings.Replace(strings.TrimSpace(s), " ", "-", -1)))
 }
 
 func MakeTitle(inpath string) string {
index 5bb69eb90d986e40b806a9d9270da01611408e7a..6939e076da202ed5dcc9fff925802f70a4f2e497 100644 (file)
@@ -60,7 +60,7 @@ type OrderedTaxonomyEntry struct {
 
 // KeyPrep... Taxonomies should be case insensitive. Can make it easily conditional later.
 func kp(in string) string {
-       return helpers.MakePath(in)
+       return helpers.MakePathToLower(in)
 }
 
 func (i Taxonomy) Get(key string) WeightedPages { return i[kp(key)] }