mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
094135ff96
commit
6abd15e781
2 changed files with 16 additions and 15 deletions
|
@ -100,25 +100,25 @@ var isFileRe = regexp.MustCompile(`.*\..{1,6}$`)
|
||||||
// GetDottedRelativePath expects a relative path starting after the content directory.
|
// GetDottedRelativePath expects a relative path starting after the content directory.
|
||||||
// It returns a relative path with dots ("..") navigating up the path structure.
|
// It returns a relative path with dots ("..") navigating up the path structure.
|
||||||
func GetDottedRelativePath(inPath string) string {
|
func GetDottedRelativePath(inPath string) string {
|
||||||
inPath = filepath.Clean(filepath.FromSlash(inPath))
|
inPath = path.Clean(filepath.ToSlash(inPath))
|
||||||
|
|
||||||
if inPath == "." {
|
if inPath == "." {
|
||||||
return "./"
|
return "./"
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, FilePathSeparator) {
|
if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, "/") {
|
||||||
inPath += FilePathSeparator
|
inPath += "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(inPath, FilePathSeparator) {
|
if !strings.HasPrefix(inPath, "/") {
|
||||||
inPath = FilePathSeparator + inPath
|
inPath = "/" + inPath
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, _ := filepath.Split(inPath)
|
dir, _ := filepath.Split(inPath)
|
||||||
|
|
||||||
sectionCount := strings.Count(dir, FilePathSeparator)
|
sectionCount := strings.Count(dir, "/")
|
||||||
|
|
||||||
if sectionCount == 0 || dir == FilePathSeparator {
|
if sectionCount == 0 || dir == "/" {
|
||||||
return "./"
|
return "./"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -142,25 +143,25 @@ var isFileRe = regexp.MustCompile(`.*\..{1,6}$`)
|
||||||
// GetDottedRelativePath expects a relative path starting after the content directory.
|
// GetDottedRelativePath expects a relative path starting after the content directory.
|
||||||
// It returns a relative path with dots ("..") navigating up the path structure.
|
// It returns a relative path with dots ("..") navigating up the path structure.
|
||||||
func GetDottedRelativePath(inPath string) string {
|
func GetDottedRelativePath(inPath string) string {
|
||||||
inPath = filepath.Clean(filepath.FromSlash(inPath))
|
inPath = path.Clean(filepath.ToSlash(inPath))
|
||||||
|
|
||||||
if inPath == "." {
|
if inPath == "." {
|
||||||
return "./"
|
return "./"
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, FilePathSeparator) {
|
if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, "/") {
|
||||||
inPath += FilePathSeparator
|
inPath += "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(inPath, FilePathSeparator) {
|
if !strings.HasPrefix(inPath, "/") {
|
||||||
inPath = FilePathSeparator + inPath
|
inPath = "/" + inPath
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, _ := filepath.Split(inPath)
|
dir, _ := path.Split(inPath)
|
||||||
|
|
||||||
sectionCount := strings.Count(dir, FilePathSeparator)
|
sectionCount := strings.Count(dir, "/")
|
||||||
|
|
||||||
if sectionCount == 0 || dir == FilePathSeparator {
|
if sectionCount == 0 || dir == "/" {
|
||||||
return "./"
|
return "./"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue