fixed relative path normalizing
This commit is contained in:
parent
8895ba969c
commit
99bc128578
2 changed files with 21 additions and 16 deletions
|
@ -59,7 +59,7 @@ func buildPageData(m Metadata, in string, out string, settings *Settings) *PageD
|
||||||
p.Title = util.PathToTitle(in)
|
p.Title = util.PathToTitle(in)
|
||||||
}
|
}
|
||||||
if icon, ok := m["icon"].(string); ok {
|
if icon, ok := m["icon"].(string); ok {
|
||||||
i, err := util.NormalizePath(icon)
|
i, err := util.NormalizePath(icon, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Icon = settings.IconName
|
p.Icon = settings.IconName
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -28,9 +28,12 @@ func ChangeExtension(in string, outExt string) string {
|
||||||
func getRoot(path string) string {
|
func getRoot(path string) string {
|
||||||
marker := ".zona.yml"
|
marker := ".zona.yml"
|
||||||
for {
|
for {
|
||||||
// fmt.Printf("check for: %s\n", candidate)
|
|
||||||
parent := filepath.Dir(path)
|
parent := filepath.Dir(path)
|
||||||
|
if parent == "/" {
|
||||||
|
panic(1)
|
||||||
|
}
|
||||||
candidate := filepath.Join(parent, marker)
|
candidate := filepath.Join(parent, marker)
|
||||||
|
// fmt.Printf("check for: %s\n", candidate)
|
||||||
if FileExists(candidate) {
|
if FileExists(candidate) {
|
||||||
return parent
|
return parent
|
||||||
} else if parent == "." {
|
} else if parent == "." {
|
||||||
|
@ -110,26 +113,28 @@ func StripTopDir(path string) string {
|
||||||
return filepath.Join(components[1:]...)
|
return filepath.Join(components[1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resolveRelativeTo(relPath string, basePath string) string {
|
||||||
|
baseDir := filepath.Dir(basePath)
|
||||||
|
combined := filepath.Join(baseDir, relPath)
|
||||||
|
resolved := filepath.Clean(combined)
|
||||||
|
return resolved
|
||||||
|
}
|
||||||
|
|
||||||
// we want to preserve a valid web-style path
|
// we want to preserve a valid web-style path
|
||||||
// and convert relative path to web-style
|
// and convert relative path to web-style
|
||||||
// so we need to see
|
// so we need to see
|
||||||
// TODO; use Rel function to get abs path between
|
func NormalizePath(target string, source string) (string, error) {
|
||||||
// the file being analyzed's path, and what lil bro
|
fmt.Printf("normalizing: %s\n", target)
|
||||||
// is pointing to
|
|
||||||
func NormalizePath(path string) (string, error) {
|
|
||||||
// empty path is root
|
// empty path is root
|
||||||
if path == "" {
|
if target == "" {
|
||||||
return "/", nil
|
return "/", nil
|
||||||
}
|
}
|
||||||
if path[0] == '.' {
|
if target[0] == '.' {
|
||||||
fmt.Println("Local path detected...")
|
resolved := resolveRelativeTo(target, source)
|
||||||
abs, err := filepath.Abs(path)
|
normalized := ReplaceRoot(resolved, "/")
|
||||||
fmt.Printf("abs: %s\n", abs)
|
fmt.Printf("Normalized: %s\n", normalized)
|
||||||
if err != nil {
|
return normalized, nil
|
||||||
return "", fmt.Errorf("Couldn't normalize path: %w", err)
|
|
||||||
}
|
|
||||||
return ReplaceRoot(abs, "/"), nil
|
|
||||||
} else {
|
} else {
|
||||||
return path, nil
|
return target, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue