File tree Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 41
41
},
42
42
"devDependencies" : {
43
43
"bit-docs-generate-html" : " ^0.6.0" ,
44
- "bit-docs-generate-searchmap" : " ^0.1.2 " ,
44
+ "bit-docs-generate-searchmap" : " ^0.1.3 " ,
45
45
"bit-docs-html-toc" : " ^0.6.0" ,
46
46
"connect" : " ^3.5.0" ,
47
47
"normalize.css" : " ^5.0.0" ,
Original file line number Diff line number Diff line change @@ -505,25 +505,33 @@ var Search = Control.extend({
505
505
numResults : numResults ,
506
506
searchValue : this . searchTerm
507
507
} , {
508
- docUrl : function ( ) {
508
+ docUrl : function ( url ) {
509
509
if ( self . options . pathPrefix ) {
510
- return self . options . pathPrefix + "/" + this . url ;
510
+ return self . options . pathPrefix + "/" + url ;
511
511
}
512
512
513
- if ( this . url . substr ( - 1 ) === "/" ) {
513
+ if ( url . substr ( - 1 ) === "/" ) {
514
514
return this . url ;
515
515
}
516
516
517
- return "/" + this . url ;
517
+ return "/" + url ;
518
518
} ,
519
- addTargetToExternalURLs : function ( html ) {
519
+ addTargetToExternalURLs : function ( html , parentHref ) {
520
520
var $html = $ ( '<div>' ) . html ( html ) ;
521
521
$html . find ( 'a' ) . each ( function ( ) {
522
522
var $a = $ ( this ) ;
523
- var a = $a [ 0 ] ;
524
- if ( a . hostname !== location . hostname || a . protocol !== location . protocol ) {
523
+ var isLocal = this . hostname === location . hostname ;
524
+ var isRelative = this . getAttribute ( 'href' ) . indexOf ( location . hostname ) === - 1 ;
525
+ if ( ! isLocal || this . protocol !== location . protocol ) {
525
526
$a . attr ( 'target' , '_blank' ) ;
526
527
}
528
+ if ( isLocal && isRelative ) {
529
+ // These links are generated by bit-docs and are relative to the page they are from
530
+ // so we need to get the path prefix of the parent a tag
531
+ var prefix = parentHref . substr ( 0 , parentHref . lastIndexOf ( '/' ) ) ;
532
+ var href = prefix + '/' + $a . attr ( 'href' ) ;
533
+ $a . attr ( 'href' , href ) ;
534
+ }
527
535
} ) ;
528
536
return $html . contents ( ) ;
529
537
}
Original file line number Diff line number Diff line change 16
16
<ul>
17
17
{{#each results as result}}
18
18
<li>
19
- <a href="{{docUrl}}" title="{{result.name}}" class="result-name">
19
+ <a href="{{docUrl(result.url) }}" title="{{result.name}}" class="result-name">
20
20
{{#if result.title}}{{result.title}}{{else}}{{result.name}}{{/if}}
21
21
22
22
30
30
31
31
{{#if result.description}}
32
32
<div class="result-description" title="{{result.description}}">
33
- {{{addTargetToExternalURLs(result.description)}}}
33
+ {{{addTargetToExternalURLs(result.description, docUrl(result.url) )}}}
34
34
</div>
35
35
{{/if}}
36
36
</a>
You can’t perform that action at this time.
0 commit comments