Simplify GetDottedRelativePath

This commit is contained in:
Bjørn Erik Pedersen 2016-03-19 17:17:17 +01:00
parent 8d86f1ec6e
commit 0a768ec95f

View file

@ -199,18 +199,19 @@ var isFileRe = regexp.MustCompile(".*\\..{1,6}$")
// Expects a relative path starting after the content directory.
func GetDottedRelativePath(inPath string) string {
inPath = filepath.Clean(filepath.FromSlash(inPath))
if inPath == "." {
return "./"
}
isFile := isFileRe.MatchString(inPath)
if !isFile {
if !strings.HasSuffix(inPath, FilePathSeparator) {
inPath += FilePathSeparator
}
if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, FilePathSeparator) {
inPath += FilePathSeparator
}
if !strings.HasPrefix(inPath, FilePathSeparator) {
inPath = FilePathSeparator + inPath
}
dir, _ := filepath.Split(inPath)
sectionCount := strings.Count(dir, FilePathSeparator)