Remove sourceRelativeLinks

Fixes #3766
This commit is contained in:
Bjørn Erik Pedersen 2017-08-02 21:37:03 +02:00
parent 481924b34d
commit 9891c0fb0e
6 changed files with 22 additions and 329 deletions

View file

@ -938,8 +938,7 @@ func setupLinkingMockSite(t *testing.T) *Site {
cfg.Set("pluralizeListTitles", false)
cfg.Set("canonifyURLs", false)
cfg.Set("blackfriday",
map[string]interface{}{
"sourceRelativeLinksProjectFolder": "/docs"})
map[string]interface{}{})
writeSourcesToSource(t, "content", fs, sources...)
return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
@ -973,134 +972,3 @@ func TestRefLinking(t *testing.T) {
// TODO: and then the failure cases.
}
func TestSourceRelativeLinksing(t *testing.T) {
t.Parallel()
site := setupLinkingMockSite(t)
type resultMap map[string]string
okresults := map[string]resultMap{
"index.md": map[string]string{
"/docs/rootfile.md": "/rootfile/",
"rootfile.md": "/rootfile/",
// See #3396 -- this may potentially be ambiguous (i.e. name conflict with home page).
// But the user have chosen so. This index.md patterns is more relevant in /sub-folders.
"index.md": "/",
"level2/2-root.md": "/level2/2-root/",
"/docs/level2/2-root.md": "/level2/2-root/",
"level2/level3/3-root.md": "/level2/level3/3-root/",
"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
"/docs/level2/2-root/": "/level2/2-root/",
"/docs/level2/2-root": "/level2/2-root/",
"/level2/2-root/": "/level2/2-root/",
"/level2/2-root": "/level2/2-root/",
}, "rootfile.md": map[string]string{
"/docs/rootfile.md": "/rootfile/",
"rootfile.md": "/rootfile/",
"level2/2-root.md": "/level2/2-root/",
"/docs/level2/2-root.md": "/level2/2-root/",
"level2/level3/3-root.md": "/level2/level3/3-root/",
"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
}, "level2/2-root.md": map[string]string{
"../rootfile.md": "/rootfile/",
"/docs/rootfile.md": "/rootfile/",
"2-root.md": "/level2/2-root/",
"../level2/2-root.md": "/level2/2-root/",
"./2-root.md": "/level2/2-root/",
"/docs/level2/2-root.md": "/level2/2-root/",
"level3/3-root.md": "/level2/level3/3-root/",
"../level2/level3/3-root.md": "/level2/level3/3-root/",
"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
}, "level2/index.md": map[string]string{
"../rootfile.md": "/rootfile/",
"/docs/rootfile.md": "/rootfile/",
"2-root.md": "/level2/2-root/",
"../level2/2-root.md": "/level2/2-root/",
"./2-root.md": "/level2/2-root/",
"/docs/level2/2-root.md": "/level2/2-root/",
"level3/3-root.md": "/level2/level3/3-root/",
"../level2/level3/3-root.md": "/level2/level3/3-root/",
"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
}, "level2/level3/3-root.md": map[string]string{
"../../rootfile.md": "/rootfile/",
"/docs/rootfile.md": "/rootfile/",
"../2-root.md": "/level2/2-root/",
"/docs/level2/2-root.md": "/level2/2-root/",
"3-root.md": "/level2/level3/3-root/",
"./3-root.md": "/level2/level3/3-root/",
"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
}, "level2/level3/index.md": map[string]string{
"../../rootfile.md": "/rootfile/",
"/docs/rootfile.md": "/rootfile/",
"../2-root.md": "/level2/2-root/",
"/docs/level2/2-root.md": "/level2/2-root/",
"3-root.md": "/level2/level3/3-root/",
"./3-root.md": "/level2/level3/3-root/",
"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
},
}
for currentFile, results := range okresults {
currentPage := findPage(site, currentFile)
if currentPage == nil {
t.Fatalf("failed to find current page in site")
}
for link, url := range results {
if out, err := site.Info.SourceRelativeLink(link, currentPage); err != nil || out != url {
t.Errorf("Expected %s to resolve to (%s), got (%s) - error: %s", link, url, out, err)
} else {
//t.Logf("tested ok %s maps to %s", link, out)
}
}
}
// TODO: and then the failure cases.
// "https://docker.com": "",
// site_test.go:1094: Expected https://docker.com to resolve to (), got () - error: Not a plain filepath link (https://docker.com)
}
func TestSourceRelativeLinkFileing(t *testing.T) {
t.Parallel()
site := setupLinkingMockSite(t)
type resultMap map[string]string
okresults := map[string]resultMap{
"index.md": map[string]string{
"/root-image.png": "/root-image.png",
"root-image.png": "/root-image.png",
}, "rootfile.md": map[string]string{
"/root-image.png": "/root-image.png",
}, "level2/2-root.md": map[string]string{
"/root-image.png": "/root-image.png",
"common.png": "/level2/common.png",
}, "level2/index.md": map[string]string{
"/root-image.png": "/root-image.png",
"common.png": "/level2/common.png",
"./common.png": "/level2/common.png",
}, "level2/level3/3-root.md": map[string]string{
"/root-image.png": "/root-image.png",
"common.png": "/level2/level3/common.png",
"../common.png": "/level2/common.png",
}, "level2/level3/index.md": map[string]string{
"/root-image.png": "/root-image.png",
"common.png": "/level2/level3/common.png",
"../common.png": "/level2/common.png",
},
}
for currentFile, results := range okresults {
currentPage := findPage(site, currentFile)
if currentPage == nil {
t.Fatalf("failed to find current page in site")
}
for link, url := range results {
if out, err := site.Info.SourceRelativeLinkFile(link, currentPage); err != nil || out != url {
t.Errorf("Expected %s to resolve to (%s), got (%s) - error: %s", link, url, out, err)
} else {
//t.Logf("tested ok %s maps to %s", link, out)
}
}
}
}