Skip to content

Commit 9891c0f

Browse files
committed
Remove sourceRelativeLinks
Fixes #3766
1 parent 481924b commit 9891c0f

File tree

6 files changed

+22
-329
lines changed

6 files changed

+22
-329
lines changed

‎helpers/content.go‎

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,31 @@ func NewContentSpec(cfg config.Provider) *ContentSpec {
6262

6363
// Blackfriday holds configuration values for Blackfriday rendering.
6464
type Blackfriday struct {
65-
Smartypants bool
66-
SmartypantsQuotesNBSP bool
67-
AngledQuotes bool
68-
Fractions bool
69-
HrefTargetBlank bool
70-
SmartDashes bool
71-
LatexDashes bool
72-
TaskLists bool
73-
PlainIDAnchors bool
74-
SourceRelativeLinksEval bool
75-
SourceRelativeLinksProjectFolder string
76-
Extensions []string
77-
ExtensionsMask []string
65+
Smartypants bool
66+
SmartypantsQuotesNBSP bool
67+
AngledQuotes bool
68+
Fractions bool
69+
HrefTargetBlank bool
70+
SmartDashes bool
71+
LatexDashes bool
72+
TaskLists bool
73+
PlainIDAnchors bool
74+
Extensions []string
75+
ExtensionsMask []string
7876
}
7977

8078
// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults.
8179
func (c ContentSpec) NewBlackfriday() *Blackfriday {
8280
defaultParam := map[string]interface{}{
83-
"smartypants": true,
84-
"angledQuotes": false,
85-
"smartypantsQuotesNBSP": false,
86-
"fractions": true,
87-
"hrefTargetBlank": false,
88-
"smartDashes": true,
89-
"latexDashes": true,
90-
"plainIDAnchors": true,
91-
"taskLists": true,
92-
"sourceRelativeLinks": false,
93-
"sourceRelativeLinksProjectFolder": "/docs/content",
81+
"smartypants": true,
82+
"angledQuotes": false,
83+
"smartypantsQuotesNBSP": false,
84+
"fractions": true,
85+
"hrefTargetBlank": false,
86+
"smartDashes": true,
87+
"latexDashes": true,
88+
"plainIDAnchors": true,
89+
"taskLists": true,
9490
}
9591

9692
ToLowerMap(defaultParam)
@@ -112,13 +108,6 @@ func (c ContentSpec) NewBlackfriday() *Blackfriday {
112108
jww.FATAL.Printf("Failed to get site rendering config\n%s", err.Error())
113109
}
114110

115-
if combinedConfig.SourceRelativeLinksEval {
116-
// Remove in Hugo 0.21
117-
Deprecated("blackfriday", "sourceRelativeLinksEval",
118-
`There is no replacement for this feature, as no developer has stepped up to the plate and volunteered to maintain this feature`, false)
119-
120-
}
121-
122111
return combinedConfig
123112
}
124113

@@ -412,8 +401,6 @@ type RenderingContext struct {
412401
DocumentName string
413402
Config *Blackfriday
414403
RenderTOC bool
415-
FileResolver FileResolverFunc
416-
LinkResolver LinkResolverFunc
417404
Cfg config.Provider
418405
}
419406

‎helpers/content_renderer.go‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/gohugoio/hugo/config"
2121
"github.com/miekg/mmark"
2222
"github.com/russross/blackfriday"
23-
jww "github.com/spf13/jwalterweatherman"
2423
)
2524

2625
type LinkResolverFunc func(ref string) (string, error)
@@ -43,35 +42,6 @@ func (r *HugoHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string
4342
}
4443
}
4544

46-
func (r *HugoHTMLRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) {
47-
if r.LinkResolver == nil || bytes.HasPrefix(link, []byte("HAHAHUGOSHORTCODE")) {
48-
// Use the blackfriday built in Link handler
49-
r.Renderer.Link(out, link, title, content)
50-
} else {
51-
// set by SourceRelativeLinksEval
52-
newLink, err := r.LinkResolver(string(link))
53-
if err != nil {
54-
newLink = string(link)
55-
jww.ERROR.Printf("LinkResolver: %s", err)
56-
}
57-
r.Renderer.Link(out, []byte(newLink), title, content)
58-
}
59-
}
60-
func (r *HugoHTMLRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
61-
if r.FileResolver == nil || bytes.HasPrefix(link, []byte("HAHAHUGOSHORTCODE")) {
62-
// Use the blackfriday built in Image handler
63-
r.Renderer.Image(out, link, title, alt)
64-
} else {
65-
// set by SourceRelativeLinksEval
66-
newLink, err := r.FileResolver(string(link))
67-
if err != nil {
68-
newLink = string(link)
69-
jww.ERROR.Printf("FileResolver: %s", err)
70-
}
71-
r.Renderer.Image(out, []byte(newLink), title, alt)
72-
}
73-
}
74-
7545
// ListItem adds task list support to the Blackfriday renderer.
7646
func (r *HugoHTMLRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
7747
if !r.Config.TaskLists {

‎helpers/content_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
188188
ctx.Config.SmartDashes = true
189189
ctx.Config.Smartypants = true
190190
ctx.Config.SmartypantsQuotesNBSP = true
191-
ctx.Config.SourceRelativeLinksEval = true
192191
renderer := c.getHTMLRenderer(defaultFlags, ctx)
193192
actualFlags := renderer.GetFlags()
194193
var expectedFlags int

‎hugolib/page.go‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -622,22 +622,11 @@ func (p *Page) setAutoSummary() error {
622622
}
623623

624624
func (p *Page) renderContent(content []byte) []byte {
625-
var fn helpers.LinkResolverFunc
626-
var fileFn helpers.FileResolverFunc
627-
if p.getRenderingConfig().SourceRelativeLinksEval {
628-
fn = func(ref string) (string, error) {
629-
return p.Site.SourceRelativeLink(ref, p)
630-
}
631-
fileFn = func(ref string) (string, error) {
632-
return p.Site.SourceRelativeLinkFile(ref, p)
633-
}
634-
}
635-
636625
return p.s.ContentSpec.RenderBytes(&helpers.RenderingContext{
637626
Content: content, RenderTOC: true, PageFmt: p.determineMarkupType(),
638627
Cfg: p.Language(),
639628
DocumentID: p.UniqueID(), DocumentName: p.Path(),
640-
Config: p.getRenderingConfig(), LinkResolver: fn, FileResolver: fileFn})
629+
Config: p.getRenderingConfig()})
641630
}
642631

643632
func (p *Page) getRenderingConfig() *helpers.Blackfriday {

‎hugolib/site.go‎

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -493,126 +493,6 @@ func (s *SiteInfo) RelRef(ref string, page *Page, options ...string) (string, er
493493
return s.refLink(ref, page, true, outputFormat)
494494
}
495495

496-
// SourceRelativeLink attempts to convert any source page relative links (like [../another.md]) into absolute links
497-
func (s *SiteInfo) SourceRelativeLink(ref string, currentPage *Page) (string, error) {
498-
var refURL *url.URL
499-
var err error
500-
501-
refURL, err = url.Parse(strings.TrimPrefix(ref, currentPage.getRenderingConfig().SourceRelativeLinksProjectFolder))
502-
if err != nil {
503-
return "", err
504-
}
505-
506-
if refURL.Scheme != "" {
507-
// Not a relative source level path
508-
return ref, nil
509-
}
510-
511-
var target *Page
512-
var link string
513-
514-
if refURL.Path != "" {
515-
refPath := filepath.Clean(filepath.FromSlash(refURL.Path))
516-
517-
if strings.IndexRune(refPath, os.PathSeparator) == 0 { // filepath.IsAbs fails to me.
518-
refPath = refPath[1:]
519-
} else {
520-
if currentPage != nil {
521-
refPath = filepath.Join(currentPage.Source.Dir(), refURL.Path)
522-
}
523-
}
524-
525-
for _, page := range s.AllRegularPages {
526-
if page.Source.Path() == refPath {
527-
target = page
528-
break
529-
}
530-
}
531-
// need to exhaust the test, then try with the others :/
532-
// if the refPath doesn't end in a filename with extension `.md`, then try with `.md` , and then `/index.md`
533-
mdPath := strings.TrimSuffix(refPath, string(os.PathSeparator)) + ".md"
534-
for _, page := range s.AllRegularPages {
535-
if page.Source.Path() == mdPath {
536-
target = page
537-
break
538-
}
539-
}
540-
indexPath := filepath.Join(refPath, "index.md")
541-
for _, page := range s.AllRegularPages {
542-
if page.Source.Path() == indexPath {
543-
target = page
544-
break
545-
}
546-
}
547-
548-
if target == nil {
549-
return "", fmt.Errorf("No page found for \"%s\" on page \"%s\".\n", ref, currentPage.Source.Path())
550-
}
551-
552-
link = target.RelPermalink()
553-
554-
}
555-
556-
if refURL.Fragment != "" {
557-
link = link + "#" + refURL.Fragment
558-
559-
if refURL.Path != "" && target != nil && !target.getRenderingConfig().PlainIDAnchors {
560-
link = link + ":" + target.UniqueID()
561-
} else if currentPage != nil && !currentPage.getRenderingConfig().PlainIDAnchors {
562-
link = link + ":" + currentPage.UniqueID()
563-
}
564-
}
565-
566-
return link, nil
567-
}
568-
569-
// SourceRelativeLinkFile attempts to convert any non-md source relative links (like [../another.gif]) into absolute links
570-
func (s *SiteInfo) SourceRelativeLinkFile(ref string, currentPage *Page) (string, error) {
571-
var refURL *url.URL
572-
var err error
573-
574-
refURL, err = url.Parse(strings.TrimPrefix(ref, currentPage.getRenderingConfig().SourceRelativeLinksProjectFolder))
575-
if err != nil {
576-
return "", err
577-
}
578-
579-
if refURL.Scheme != "" {
580-
// Not a relative source level path
581-
return ref, nil
582-
}
583-
584-
var target *source.File
585-
var link string
586-
587-
if refURL.Path != "" {
588-
refPath := filepath.Clean(filepath.FromSlash(refURL.Path))
589-
590-
if strings.IndexRune(refPath, os.PathSeparator) == 0 { // filepath.IsAbs fails to me.
591-
refPath = refPath[1:]
592-
} else {
593-
if currentPage != nil {
594-
refPath = filepath.Join(currentPage.Source.Dir(), refURL.Path)
595-
}
596-
}
597-
598-
for _, file := range *s.Files {
599-
if file.Path() == refPath {
600-
target = file
601-
break
602-
}
603-
}
604-
605-
if target == nil {
606-
return "", fmt.Errorf("No file found for \"%s\" on page \"%s\".\n", ref, currentPage.Source.Path())
607-
}
608-
609-
link = target.Path()
610-
return "/" + filepath.ToSlash(link), nil
611-
}
612-
613-
return "", fmt.Errorf("failed to find a file to match \"%s\" on page \"%s\"", ref, currentPage.Source.Path())
614-
}
615-
616496
func (s *SiteInfo) addToPaginationPageCount(cnt uint64) {
617497
atomic.AddUint64(&s.paginationPageCount, cnt)
618498
}

0 commit comments

Comments
 (0)