mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-30 01:43:32 -05:00
#462 fix, remove leading and trailing dashes from urlized slug. includes test changes
This commit is contained in:
parent
f52e662890
commit
4b9e4c90d9
2 changed files with 14 additions and 6 deletions
|
@ -46,7 +46,7 @@ Leading
|
||||||
"Development",
|
"Development",
|
||||||
"VIM"
|
"VIM"
|
||||||
],
|
],
|
||||||
"slug": "spf13-vim-3-0-release-and-new-website"
|
"slug": "-spf13-vim-3-0-release-and-new-website-"
|
||||||
}
|
}
|
||||||
|
|
||||||
Content of the file goes Here
|
Content of the file goes Here
|
||||||
|
@ -566,13 +566,13 @@ func TestLayoutOverride(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSliceToLower(t *testing.T) {
|
func TestSliceToLower(t *testing.T) {
|
||||||
tests := []struct{
|
tests := []struct {
|
||||||
value []string
|
value []string
|
||||||
expected []string
|
expected []string
|
||||||
}{
|
}{
|
||||||
{[]string{"a","b","c"}, []string{"a", "b", "c"}},
|
{[]string{"a", "b", "c"}, []string{"a", "b", "c"}},
|
||||||
{[]string{"a","B","c"}, []string{"a", "b", "c"}},
|
{[]string{"a", "B", "c"}, []string{"a", "b", "c"}},
|
||||||
{[]string{"A","B","C"}, []string{"a", "b", "c"}},
|
{[]string{"A", "B", "C"}, []string{"a", "b", "c"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
|
@ -128,6 +128,14 @@ func pageToPermalinkFilename(p *Page, _ string) (string, error) {
|
||||||
// if the page has a slug, return the slug, else return the title
|
// if the page has a slug, return the slug, else return the title
|
||||||
func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
|
func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
|
||||||
if p.Slug != "" {
|
if p.Slug != "" {
|
||||||
|
// Don't start or end with a -
|
||||||
|
if strings.HasPrefix(p.Slug, "-") {
|
||||||
|
p.Slug = p.Slug[1:len(p.Slug)]
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(p.Slug, "-") {
|
||||||
|
p.Slug = p.Slug[0 : len(p.Slug)-1]
|
||||||
|
}
|
||||||
return p.Slug, nil
|
return p.Slug, nil
|
||||||
}
|
}
|
||||||
return pageToPermalinkTitle(p, a)
|
return pageToPermalinkTitle(p, a)
|
||||||
|
|
Loading…
Reference in a new issue