Fix pathing with relative non-single-depth root

This commit is contained in:
Bel LaPointe
2019-11-14 11:14:57 -07:00
parent 7964518d36
commit e6f63a578f
4 changed files with 100 additions and 35 deletions

View File

@@ -16,16 +16,10 @@ type Path struct {
}
func NewPathFromLocal(p string) Path {
if !strings.HasPrefix(p, "/") {
cwd, _ := os.Getwd()
p = path.Clean(path.Join(cwd, p))
}
splits := strings.SplitN(p, path.Base(config.Root), 2)
splits := strings.SplitN(p, path.Base(config.Root)+"/", 2)
href := splits[0]
if len(splits) > 1 && (splits[0] == "" || splits[0] == "/") {
href = splits[1]
} else {
href = strings.Join(splits, path.Base(config.Root))
}
href = path.Join("/notes", href)
return NewPathFromURL(href)