Fix absolute and relative without parent dir paths work
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user