summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-08-02 21:37:03 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-08-02 22:04:38 +0200
commit9891c0fb0eb274b8a95b62c40070a87a6e04088c (patch)
tree16c12115fceda9ef39e43dc3f7c6eee5965dc840 /hugolib
parent481924b34d23b0ce435778cce7bce77571b22f9d (diff)
Remove sourceRelativeLinks
Fixes #3766
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page.go13
-rw-r--r--hugolib/site.go120
-rw-r--r--hugolib/site_test.go134
3 files changed, 2 insertions, 265 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 9937be325..0120d6ef0 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -622,22 +622,11 @@ func (p *Page) setAutoSummary() error {
}
func (p *Page) renderContent(content []byte) []byte {
- var fn helpers.LinkResolverFunc
- var fileFn helpers.FileResolverFunc
- if p.getRenderingConfig().SourceRelativeLinksEval {
- fn = func(ref string) (string, error) {
- return p.Site.SourceRelativeLink(ref, p)
- }
- fileFn = func(ref string) (string, error) {
- return p.Site.SourceRelativeLinkFile(ref, p)
- }
- }
-
return p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
Content: content, RenderTOC: true, PageFmt: p.determineMarkupType(),
Cfg: p.Language(),
DocumentID: p.UniqueID(), DocumentName: p.Path(),
- Config: p.getRenderingConfig(), LinkResolver: fn, FileResolver: fileFn})
+ Config: p.getRenderingConfig()})
}
func (p *Page) getRenderingConfig() *helpers.Blackfriday {
diff --git a/hugolib/site.go b/hugolib/site.go
index 8bf37e17d..13ca7f144 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -493,126 +493,6 @@ func (s *SiteInfo) RelRef(ref string, page *Page, options ...string) (string, er
return s.refLink(ref, page, true, outputFormat)
}
-// SourceRelativeLink attempts to convert any source page relative links (like [../another.md]) into absolute links
-func (s *SiteInfo) SourceRelativeLink(ref string, currentPage *Page) (string, error) {
- var refURL *url.URL
- var err error
-
- refURL, err = url.Parse(strings.TrimPrefix(ref, currentPage.getRenderingConfig().SourceRelativeLinksProjectFolder))
- if err != nil {
- return "", err
- }
-
- if refURL.Scheme != "" {
- // Not a relative source level path
- return ref, nil
- }
-
- var target *Page
- var link string
-
- if refURL.Path != "" {
- refPath := filepath.Clean(filepath.FromSlash(refURL.Path))
-
- if strings.IndexRune(refPath, os.PathSeparator) == 0 { // filepath.IsAbs fails to me.
- refPath = refPath[1:]
- } else {
- if currentPage != nil {
- refPath = filepath.Join(currentPage.Source.Dir(), refURL.Path)
- }
- }
-
- for _, page := range s.AllRegularPages {
- if page.Source.Path() == refPath {
- target = page
- break
- }
- }
- // need to exhaust the test, then try with the others :/
- // if the refPath doesn't end in a filename with extension `.md`, then try with `.md` , and then `/index.md`
- mdPath := strings.TrimSuffix(refPath, string(os.PathSeparator)) + ".md"
- for _, page := range s.AllRegularPages {
- if page.Source.Path() == mdPath {
- target = page
- break
- }
- }
- indexPath := filepath.Join(refPath, "index.md")
- for _, page := range s.AllRegularPages {
- if page.Source.Path() == indexPath {
- target = page
- break
- }
- }
-
- if target == nil {
- return "", fmt.Errorf("No page found for \"%s\" on page \"%s\".\n", ref, currentPage.Source.Path())
- }
-
- link = target.RelPermalink()
-
- }
-
- if refURL.Fragment != "" {
- link = link + "#" + refURL.Fragment
-
- if refURL.Path != "" && target != nil && !target.getRenderingConfig().PlainIDAnchors {
- link = link + ":" + target.UniqueID()
- } else if currentPage != nil && !currentPage.getRenderingConfig().PlainIDAnchors {
- link = link + ":" + currentPage.UniqueID()
- }
- }
-
- return link, nil
-}
-
-// SourceRelativeLinkFile attempts to convert any non-md source relative links (like [../another.gif]) into absolute links
-func (s *SiteInfo) SourceRelativeLinkFile(ref string, currentPage *Page) (string, error) {
- var refURL *url.URL
- var err error
-
- refURL, err = url.Parse(strings.TrimPrefix(ref, currentPage.getRenderingConfig().SourceRelativeLinksProjectFolder))
- if err != nil {
- return "", err
- }
-
- if refURL.Scheme != "" {
- // Not a relative source level path
- return ref, nil
- }
-
- var target *source.File
- var link string
-
- if refURL.Path != "" {
- refPath := filepath.Clean(filepath.FromSlash(refURL.Path))
-
- if strings.IndexRune(refPath, os.PathSeparator) == 0 { // filepath.IsAbs fails to me.
- refPath = refPath[1:]
- } else {
- if currentPage != nil {
- refPath = filepath.Join(currentPage.Source.Dir(), refURL.Path)
- }
- }
-
- for _, file := range *s.Files {
- if file.Path() == refPath {
- target = file
- break
- }
- }
-
- if target == nil {
- return "", fmt.Errorf("No file found for \"%s\" on page \"%s\".\n", ref, currentPage.Source.Path())
- }
-
- link = target.Path()
- return "/" + filepath.ToSlash(link), nil
- }
-
- return "", fmt.Errorf("failed to find a file to match \"%s\" on page \"%s\"", ref, currentPage.Source.Path())
-}
-
func (s *SiteInfo) addToPaginationPageCount(cnt uint64) {
atomic.AddUint64(&s.paginationPageCount, cnt)
}
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
index bffdec1a9..d7ca66827 100644
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -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)
- }
- }
- }
-}