mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 07:00:31 +03:00
strip trailing baseurl slash. Added a new template function "sanitizeurl" which ensures no double slashes. Fixed #221
This commit is contained in:
parent
a6170154cf
commit
ad34be9d77
3 changed files with 32 additions and 19 deletions
|
@ -16,8 +16,18 @@ package helpers
|
|||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"github.com/PuerkitoBio/purell"
|
||||
)
|
||||
|
||||
func SanitizeUrl(in string) string {
|
||||
url, err := purell.NormalizeURLString(in, purell.FlagsUsuallySafeGreedy|purell.FlagRemoveDuplicateSlashes|purell.FlagRemoveUnnecessaryHostDots|purell.FlagRemoveEmptyPortSeparator)
|
||||
if err != nil {
|
||||
return in
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
// Similar to MakePath, but with Unicode handling
|
||||
// Example:
|
||||
// uri: Vim (text editor)
|
||||
|
@ -55,6 +65,7 @@ func MakePermalink(host, plink string) *url.URL {
|
|||
}
|
||||
|
||||
func UrlPrep(ugly bool, in string) string {
|
||||
in = SanitizeUrl(in)
|
||||
if ugly {
|
||||
return Uglify(in)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue