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. // Expects a relative path starting after the content directory.
func GetDottedRelativePath(inPath string) string { func GetDottedRelativePath(inPath string) string {
inPath = filepath.Clean(filepath.FromSlash(inPath)) inPath = filepath.Clean(filepath.FromSlash(inPath))
if inPath == "." { if inPath == "." {
return "./" return "./"
} }
isFile := isFileRe.MatchString(inPath)
if !isFile { if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, FilePathSeparator) {
if !strings.HasSuffix(inPath, FilePathSeparator) {
inPath += FilePathSeparator inPath += FilePathSeparator
} }
}
if !strings.HasPrefix(inPath, FilePathSeparator) { if !strings.HasPrefix(inPath, FilePathSeparator) {
inPath = FilePathSeparator + inPath inPath = FilePathSeparator + inPath
} }
dir, _ := filepath.Split(inPath) dir, _ := filepath.Split(inPath)
sectionCount := strings.Count(dir, FilePathSeparator) sectionCount := strings.Count(dir, FilePathSeparator)