Fix absolute and relative without parent dir paths work
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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)
|
||||
}
|
||||
|
||||
1
public/A/D/G/A/b
Executable file
1
public/A/D/G/A/b
Executable file
@@ -0,0 +1 @@
|
||||
asdf
|
||||
1
public/A/abc
Executable file
1
public/A/abc
Executable file
@@ -0,0 +1 @@
|
||||
asdf
|
||||
1
public/A/asdf
Executable file
1
public/A/asdf
Executable file
@@ -0,0 +1 @@
|
||||
asdf
|
||||
12
public/A/x
Executable file
12
public/A/x
Executable file
@@ -0,0 +1,12 @@
|
||||
# A.x
|
||||
|
||||
| hello | world |
|
||||
|-------|-------|
|
||||
| cont | ent. |
|
||||
|
||||
## A.X
|
||||
|
||||
1
|
||||
2
|
||||
|
||||
3
|
||||
5
public/B/y
Executable file
5
public/B/y
Executable file
@@ -0,0 +1,5 @@
|
||||
## B.y
|
||||
|
||||
| hello | world |
|
||||
|-------|-------|
|
||||
| cont | ent. |
|
||||
8
public/B/z
Executable file
8
public/B/z
Executable file
@@ -0,0 +1,8 @@
|
||||
## B.z
|
||||
|
||||
| hello | world |
|
||||
|-------|-------|
|
||||
| cont | ent. |
|
||||
|
||||
|
||||
HI
|
||||
1
public/D/E/F/g
Executable file
1
public/D/E/F/g
Executable file
@@ -0,0 +1 @@
|
||||
hi
|
||||
Reference in New Issue
Block a user