From 0a768ec95fc44c680c69530e515e11a02196b3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 19 Mar 2016 17:17:17 +0100 Subject: [PATCH] Simplify GetDottedRelativePath --- helpers/path.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/helpers/path.go b/helpers/path.go index 75e46f552..d9efeb24e 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -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)