1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 07:24:39 +01:00
gojekyll/helpers/path.go
2017-06-28 19:12:23 -04:00

26 lines
534 B
Go

package helpers
import (
"path"
"strings"
)
// TrimExt returns a path without its extension, if any
func TrimExt(name string) string {
return name[:len(name)-len(path.Ext(name))]
}
// URLPathClean removes internal // etc. Unlike path.Clean, it
// leaves the final "/" intact.
func URLPathClean(url string) string {
finalSlash := false
if strings.HasSuffix(url, "/") && len(url) > 1 {
finalSlash = true
}
cleaned := path.Clean(url)
if finalSlash && !strings.HasSuffix(cleaned, "/") {
cleaned += "/"
}
return cleaned
}