Simplify GetDottedRelativePath
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 19 Mar 2016 16:17:17 +0000 (17:17 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 19 Mar 2016 16:17:17 +0000 (17:17 +0100)
helpers/path.go

index 75e46f5529f820e2657a369ceea4757311653a51..d9efeb24e79c42d602fa0d85333e6fba991e144f 100644 (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)