// GetDottedRelativePath expects a relative path starting after the content directory.
// It returns a relative path with dots ("..") navigating up the path structure.
func GetDottedRelativePath(inPath string) string {
- inPath = filepath.Clean(filepath.FromSlash(inPath))
+ inPath = path.Clean(filepath.ToSlash(inPath))
if inPath == "." {
return "./"
}
- if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, FilePathSeparator) {
- inPath += FilePathSeparator
+ if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, "/") {
+ inPath += "/"
}
- if !strings.HasPrefix(inPath, FilePathSeparator) {
- inPath = FilePathSeparator + inPath
+ if !strings.HasPrefix(inPath, "/") {
+ inPath = "/" + inPath
}
dir, _ := filepath.Split(inPath)
- sectionCount := strings.Count(dir, FilePathSeparator)
+ sectionCount := strings.Count(dir, "/")
- if sectionCount == 0 || dir == FilePathSeparator {
+ if sectionCount == 0 || dir == "/" {
return "./"
}
"fmt"
"io"
"os"
+ "path"
"path/filepath"
"regexp"
"sort"
// GetDottedRelativePath expects a relative path starting after the content directory.
// It returns a relative path with dots ("..") navigating up the path structure.
func GetDottedRelativePath(inPath string) string {
- inPath = filepath.Clean(filepath.FromSlash(inPath))
+ inPath = path.Clean(filepath.ToSlash(inPath))
if inPath == "." {
return "./"
}
- if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, FilePathSeparator) {
- inPath += FilePathSeparator
+ if !isFileRe.MatchString(inPath) && !strings.HasSuffix(inPath, "/") {
+ inPath += "/"
}
- if !strings.HasPrefix(inPath, FilePathSeparator) {
- inPath = FilePathSeparator + inPath
+ if !strings.HasPrefix(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 "./"
}