mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 22:09:57 -05:00
Fix #302. Links now have trailing slashes.
This commit is contained in:
parent
a31edb3388
commit
30af267b32
2 changed files with 14 additions and 9 deletions
|
@ -23,7 +23,7 @@ import (
|
|||
)
|
||||
|
||||
func SanitizeUrl(in string) string {
|
||||
url, err := purell.NormalizeURLString(in, purell.FlagsUsuallySafeGreedy|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
url, err := purell.NormalizeURLString(in, purell.FlagsSafe|purell.FlagRemoveTrailingSlash|purell.FlagRemoveDotSegments|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
if err != nil {
|
||||
return in
|
||||
}
|
||||
|
@ -79,11 +79,16 @@ func MakePermalink(host, plink string) *url.URL {
|
|||
}
|
||||
|
||||
func UrlPrep(ugly bool, in string) string {
|
||||
in = SanitizeUrl(in)
|
||||
if ugly {
|
||||
return Uglify(in)
|
||||
x := Uglify(SanitizeUrl(in))
|
||||
return x
|
||||
} else {
|
||||
return PrettifyUrl(in)
|
||||
x := PrettifyUrl(SanitizeUrl(in))
|
||||
url, err := purell.NormalizeURLString(x, purell.FlagAddTrailingSlash)
|
||||
if err != nil {
|
||||
return in
|
||||
}
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ func TestPermalink(t *testing.T) {
|
|||
expectedAbs string
|
||||
expectedRel string
|
||||
}{
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", "", false, "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", "", false, "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", "", false, "/x/y/z/boofar/", "/x/y/z/boofar/"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", "", false, "/x/y/z/boofar/", "/x/y/z/boofar/"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", "", false, "/x/y/z/boofar/", "/x/y/z/boofar/"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", "", false, "http://barnew/x/y/z/boofar/", "/x/y/z/boofar/"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", "", false, "http://barnew/x/y/z/boofar/", "/x/y/z/boofar/"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
|
|
Loading…
Reference in a new issue