1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 14:37:50 +01:00
gojekyll/utils/urls.go

22 lines
444 B
Go
Raw Permalink Normal View History

2017-07-12 15:52:40 +02:00
package utils
import "strings"
// URLJoin interpolates paths with "/", skipping empty paths and avoiding "//".
func URLJoin(paths ...string) string {
url := ""
loop:
for _, p := range paths {
switch {
case p == "":
continue loop
case url != "" && !strings.HasSuffix(url, "/") && !strings.HasPrefix(p, "/"):
url += "/"
case strings.HasSuffix(url, "/") && strings.HasPrefix(p, "/"):
p = p[1:]
}
url += p
}
return url
}