diff options
author | spf13 <steve.francia@gmail.com> | 2014-08-25 12:11:19 -0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-08-25 12:45:47 -0400 |
commit | 30af267b32dcbf07cd382c1541a6cfd18c5e7c89 (patch) | |
tree | 2c0c4a9150b3893e44c2deaedd7a92876a122593 | |
parent | a31edb3388606eb231261780d91e1324c50b2953 (diff) |
Fix #302. Links now have trailing slashes.
-rw-r--r-- | helpers/url.go | 13 | ||||
-rw-r--r-- | hugolib/page_permalink_test.go | 10 |
2 files changed, 14 insertions, 9 deletions
diff --git a/helpers/url.go b/helpers/url.go index 8a33c5b86..048832058 100644 --- a/helpers/url.go +++ b/helpers/url.go @@ -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 } } diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go index be88c2faf..b20362d5e 100644 --- a/hugolib/page_permalink_test.go +++ b/hugolib/page_permalink_test.go @@ -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"}, |