Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrongzhang <chrongzhang@tencent.com>2015-09-01 15:53:25 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-09-01 16:26:02 +0300
commit52d94fa67578f6b63035e73b236ca8abd40d0006 (patch)
treea91a2c1ee95ec979e9d7e92054f4f1cfd712040a /helpers
parent49fe04c0bd8111bf686d9205d543f8651ea24cfc (diff)
Add config option "disablePathToLower"
Enabling this prevents lowercasing of the path/url. Fixes #557
Diffstat (limited to 'helpers')
-rw-r--r--helpers/path.go12
-rw-r--r--helpers/path_test.go33
-rw-r--r--helpers/url.go2
3 files changed, 39 insertions, 8 deletions
diff --git a/helpers/path.go b/helpers/path.go
index a9d488469..fc3262473 100644
--- a/helpers/path.go
+++ b/helpers/path.go
@@ -78,11 +78,13 @@ func MakePath(s string) string {
return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1))
}
-// MakePathToLower creates a Unicode-sanitized string, with the spaces replaced,
-// and transformed to lower case.
-// E.g. Social Media -> social-media
-func MakePathToLower(s string) string {
- return strings.ToLower(MakePath(s))
+// MakePathSanitized creates a Unicode-sanitized string, with the spaces replaced
+func MakePathSanitized(s string) string {
+ if viper.GetBool("DisablePathToLower") {
+ return MakePath(s)
+ } else {
+ return strings.ToLower(MakePath(s))
+ }
}
func MakeTitle(inpath string) string {
diff --git a/helpers/path_test.go b/helpers/path_test.go
index 85e4e0f10..95171165f 100644
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -42,7 +42,10 @@ func TestMakePath(t *testing.T) {
}
}
-func TestMakePathToLower(t *testing.T) {
+func TestMakePathSanitized(t *testing.T) {
+ viper.Reset()
+ defer viper.Reset()
+
tests := []struct {
input string
expected string
@@ -54,8 +57,34 @@ func TestMakePathToLower(t *testing.T) {
{"трям/трям", "трям/трям"},
{"은행", "은행"},
}
+
+ for _, test := range tests {
+ output := MakePathSanitized(test.input)
+ if output != test.expected {
+ t.Errorf("Expected %#v, got %#v\n", test.expected, output)
+ }
+ }
+}
+
+func TestMakePathSanitizedDisablePathToLower(t *testing.T) {
+ viper.Reset()
+ defer viper.Reset()
+ viper.Set("DisablePathToLower", true)
+
+ 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 := MakePathToLower(test.input)
+ output := MakePathSanitized(test.input)
if output != test.expected {
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
}
diff --git a/helpers/url.go b/helpers/url.go
index 415f11b74..c3365d0b8 100644
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -102,7 +102,7 @@ func SanitizeURLKeepTrailingSlash(in string) string {
// uri: Vim (text editor)
// urlize: vim-text-editor
func URLize(uri string) string {
- sanitized := MakePathToLower(uri)
+ sanitized := MakePathSanitized(uri)
// escape unicode letters
parsedUri, err := url.Parse(sanitized)