Fix absolute and relative without parent dir paths work
parent
9fc4e63a34
commit
3079cd163f
|
|
@ -1,4 +1,5 @@
|
|||
gollum
|
||||
public
|
||||
**.sw*
|
||||
**/**.sw*
|
||||
*.sw*
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
26
main_test.go
26
main_test.go
|
|
@ -16,16 +16,26 @@ import (
|
|||
)
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
makeFiles(t)
|
||||
defer os.RemoveAll(config.Root)
|
||||
log.Println(config.Root)
|
||||
s := makeServer(t)
|
||||
defer s.Close()
|
||||
testServer(t, s.URL)
|
||||
for _, basedir := range []string{os.TempDir(), "./tempDir"} {
|
||||
os.MkdirAll(basedir, os.ModePerm)
|
||||
makeFiles(t, basedir)
|
||||
if basedir[0] == '.' && config.Root[0] != '.' {
|
||||
config.Root = "./" + config.Root
|
||||
}
|
||||
defer os.RemoveAll(config.Root)
|
||||
log.Println(config.Root)
|
||||
t.Log("trying with root", config.Root)
|
||||
s := makeServer(t)
|
||||
defer s.Close()
|
||||
testServer(t, s.URL)
|
||||
if basedir[0] == '.' {
|
||||
os.RemoveAll(basedir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func makeFiles(t *testing.T) {
|
||||
d, err := ioutil.TempDir(os.TempDir(), "pattern*")
|
||||
func makeFiles(t *testing.T, basedir string) {
|
||||
d, err := ioutil.TempDir(basedir, "pattern*")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
asdf
|
||||
|
|
@ -0,0 +1 @@
|
|||
asdf
|
||||
|
|
@ -0,0 +1 @@
|
|||
asdf
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
# A.x
|
||||
|
||||
| hello | world |
|
||||
|-------|-------|
|
||||
| cont | ent. |
|
||||
|
||||
## A.X
|
||||
|
||||
1
|
||||
2
|
||||
|
||||
3
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
## B.y
|
||||
|
||||
| hello | world |
|
||||
|-------|-------|
|
||||
| cont | ent. |
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
## B.z
|
||||
|
||||
| hello | world |
|
||||
|-------|-------|
|
||||
| cont | ent. |
|
||||
|
||||
|
||||
HI
|
||||
|
|
@ -0,0 +1 @@
|
|||
hi
|
||||
Loading…
Reference in New Issue