mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-11 01:27:54 +00:00
Add config option "disablePathToLower"
Enabling this prevents lowercasing of the path/url. Fixes #557
This commit is contained in:
parent
49fe04c0bd
commit
52d94fa675
7 changed files with 45 additions and 11 deletions
|
@ -160,6 +160,7 @@ func LoadDefaultSettings() {
|
||||||
viper.SetDefault("Blackfriday", helpers.NewBlackfriday())
|
viper.SetDefault("Blackfriday", helpers.NewBlackfriday())
|
||||||
viper.SetDefault("RSSUri", "index.xml")
|
viper.SetDefault("RSSUri", "index.xml")
|
||||||
viper.SetDefault("SectionPagesMenu", "")
|
viper.SetDefault("SectionPagesMenu", "")
|
||||||
|
viper.SetDefault("DisablePathToLower", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeConfig initializes a config file with sensible default configuration flags.
|
// InitializeConfig initializes a config file with sensible default configuration flags.
|
||||||
|
|
|
@ -133,6 +133,8 @@ Following is a list of Hugo-defined variables that you can configure and their c
|
||||||
title: ""
|
title: ""
|
||||||
# if true, use /filename.html instead of /filename/
|
# if true, use /filename.html instead of /filename/
|
||||||
uglyURLs: false
|
uglyURLs: false
|
||||||
|
# Do not make the url/path to lowercase
|
||||||
|
disablePathToLower: false
|
||||||
# verbose output
|
# verbose output
|
||||||
verbose: false
|
verbose: false
|
||||||
# verbose logging
|
# verbose logging
|
||||||
|
|
|
@ -78,11 +78,13 @@ func MakePath(s string) string {
|
||||||
return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1))
|
return UnicodeSanitize(strings.Replace(strings.TrimSpace(s), " ", "-", -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakePathToLower creates a Unicode-sanitized string, with the spaces replaced,
|
// MakePathSanitized creates a Unicode-sanitized string, with the spaces replaced
|
||||||
// and transformed to lower case.
|
func MakePathSanitized(s string) string {
|
||||||
// E.g. Social Media -> social-media
|
if viper.GetBool("DisablePathToLower") {
|
||||||
func MakePathToLower(s string) string {
|
return MakePath(s)
|
||||||
return strings.ToLower(MakePath(s))
|
} else {
|
||||||
|
return strings.ToLower(MakePath(s))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeTitle(inpath string) string {
|
func MakeTitle(inpath string) string {
|
||||||
|
|
|
@ -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 {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
|
@ -54,8 +57,34 @@ func TestMakePathToLower(t *testing.T) {
|
||||||
{"трям/трям", "трям/трям"},
|
{"трям/трям", "трям/трям"},
|
||||||
{"은행", "은행"},
|
{"은행", "은행"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 := MakePathSanitized(test.input)
|
||||||
if output != test.expected {
|
if output != test.expected {
|
||||||
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
|
t.Errorf("Expected %#v, got %#v\n", test.expected, output)
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ func SanitizeURLKeepTrailingSlash(in string) string {
|
||||||
// uri: Vim (text editor)
|
// uri: Vim (text editor)
|
||||||
// urlize: vim-text-editor
|
// urlize: vim-text-editor
|
||||||
func URLize(uri string) string {
|
func URLize(uri string) string {
|
||||||
sanitized := MakePathToLower(uri)
|
sanitized := MakePathSanitized(uri)
|
||||||
|
|
||||||
// escape unicode letters
|
// escape unicode letters
|
||||||
parsedUri, err := url.Parse(sanitized)
|
parsedUri, err := url.Parse(sanitized)
|
||||||
|
|
|
@ -1045,7 +1045,7 @@ func (s *Site) newTaxonomyNode(t taxRenderInfo) (*Node, string) {
|
||||||
key := t.key
|
key := t.key
|
||||||
n := s.NewNode()
|
n := s.NewNode()
|
||||||
if s.Info.preserveTaxonomyNames {
|
if s.Info.preserveTaxonomyNames {
|
||||||
key = helpers.MakePathToLower(key)
|
key = helpers.MakePathSanitized(key)
|
||||||
// keep as is, just make sure the first char is upper
|
// keep as is, just make sure the first char is upper
|
||||||
n.Title = helpers.FirstUpper(t.key)
|
n.Title = helpers.FirstUpper(t.key)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1188,7 +1188,7 @@ func (s *Site) RenderSectionLists() error {
|
||||||
[]string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"})
|
[]string{"section/" + section + ".html", "_default/section.html", "_default/list.html", "indexes/" + section + ".html", "_default/indexes.html"})
|
||||||
|
|
||||||
if s.Info.preserveTaxonomyNames {
|
if s.Info.preserveTaxonomyNames {
|
||||||
section = helpers.MakePathToLower(section)
|
section = helpers.MakePathSanitized(section)
|
||||||
}
|
}
|
||||||
|
|
||||||
n := s.newSectionListNode(sectionName, section, data)
|
n := s.newSectionListNode(sectionName, section, data)
|
||||||
|
|
|
@ -60,7 +60,7 @@ type OrderedTaxonomyEntry struct {
|
||||||
|
|
||||||
// KeyPrep... Taxonomies should be case insensitive. Can make it easily conditional later.
|
// KeyPrep... Taxonomies should be case insensitive. Can make it easily conditional later.
|
||||||
func kp(in string) string {
|
func kp(in string) string {
|
||||||
return helpers.MakePathToLower(in)
|
return helpers.MakePathSanitized(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Taxonomy) Get(key string) WeightedPages { return i[kp(key)] }
|
func (i Taxonomy) Get(key string) WeightedPages { return i[kp(key)] }
|
||||||
|
|
Loading…
Add table
Reference in a new issue