@@ -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-
616496func (s * SiteInfo ) addToPaginationPageCount (cnt uint64 ) {
617497 atomic .AddUint64 (& s .paginationPageCount , cnt )
618498}
0 commit comments