mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Simplify GetDottedRelativePath
This commit is contained in:
parent
8d86f1ec6e
commit
0a768ec95f
1 changed files with 6 additions and 5 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue