Fix absolute and relative without parent dir paths work
parent
9fc4e63a34
commit
3079cd163f
|
|
@ -1,4 +1,5 @@
|
||||||
gollum
|
gollum
|
||||||
|
public
|
||||||
**.sw*
|
**.sw*
|
||||||
**/**.sw*
|
**/**.sw*
|
||||||
*.sw*
|
*.sw*
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@ type Path struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPathFromLocal(p string) Path {
|
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]
|
href := splits[0]
|
||||||
if len(splits) > 1 && (splits[0] == "" || splits[0] == "/") {
|
if len(splits) > 1 && (splits[0] == "" || splits[0] == "/") {
|
||||||
href = splits[1]
|
href = splits[1]
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ func TestNewPathFromLocal(t *testing.T) {
|
||||||
href string
|
href string
|
||||||
local 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",
|
in: "/wiki/b/a.md",
|
||||||
root: "/wiki",
|
root: "/wiki",
|
||||||
|
|
|
||||||
26
main_test.go
26
main_test.go
|
|
@ -16,16 +16,26 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAll(t *testing.T) {
|
func TestAll(t *testing.T) {
|
||||||
makeFiles(t)
|
for _, basedir := range []string{os.TempDir(), "./tempDir"} {
|
||||||
defer os.RemoveAll(config.Root)
|
os.MkdirAll(basedir, os.ModePerm)
|
||||||
log.Println(config.Root)
|
makeFiles(t, basedir)
|
||||||
s := makeServer(t)
|
if basedir[0] == '.' && config.Root[0] != '.' {
|
||||||
defer s.Close()
|
config.Root = "./" + config.Root
|
||||||
testServer(t, s.URL)
|
}
|
||||||
|
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) {
|
func makeFiles(t *testing.T, basedir string) {
|
||||||
d, err := ioutil.TempDir(os.TempDir(), "pattern*")
|
d, err := ioutil.TempDir(basedir, "pattern*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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