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
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
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