Fix absolute and relative without parent dir paths work

This commit is contained in:
Bel LaPointe
2019-11-21 12:28:30 -07:00
parent 9fc4e63a34
commit 3079cd163f
11 changed files with 59 additions and 9 deletions

View File

@@ -16,7 +16,11 @@ type Path struct {
}
func NewPathFromLocal(p string) Path {
splits := strings.SplitN(p, path.Base(config.Root)+"/", 2)
root := config.Root + "/"
if strings.HasPrefix(root, "./") {
root = root[2:]
}
splits := strings.SplitN(p, root, 2)
href := splits[0]
if len(splits) > 1 && (splits[0] == "" || splits[0] == "/") {
href = splits[1]

View File

@@ -32,6 +32,12 @@ func TestNewPathFromLocal(t *testing.T) {
href string
local string
}{
{
in: "/wiki/wiki/b/a.md",
root: "/wiki/wiki",
href: "/notes/b/a.md",
local: "/wiki/wiki/b/a.md",
},
{
in: "/wiki/b/a.md",
root: "/wiki",