@@ -135,7 +135,7 @@ module.exports = function dabFactory(ngIoProjPath) {
135135 assert ( depth === 1 || depth == 2 , 'depth ' + depth ) ;
136136 const jadeFilePath = path . resolve ( outFileNoExtn + '.jade' ) ;
137137 const breadcrumbs = $ ( 'header > nav ol.breadcrumbs' ) ;
138- fs . writeFileSync ( jadeFilePath , apiEntryJadeTemplate ( depth , breadcrumbs , div ) ) ;
138+ fs . writeFileSync ( jadeFilePath , apiEntryJadeTemplate ( $ , depth , breadcrumbs , div ) ) ;
139139 // In case harp cached the .html version, remove it since it will be generated.
140140 try {
141141 fs . unlinkSync ( path . resolve ( outFileNoExtn + '.html' ) ) ;
@@ -197,17 +197,29 @@ module.exports = function dabFactory(ngIoProjPath) {
197197 return _self ;
198198} ;
199199
200+ function _adjustAnchorHref ( $ , $elt , hrefPathPrefix ) {
201+ if ( ! hrefPathPrefix ) return ;
202+ $elt . find ( 'a[href]' ) . each ( ( i , e ) => {
203+ let href = $ ( e ) . attr ( 'href' )
204+ // Do nothing to absolute or external links
205+ if ( href . match ( / ^ \/ | ^ [ a - z ] + : / ) ) return ;
206+ $ ( e ) . attr ( 'href' , `${ hrefPathPrefix } /${ href } ` ) ;
207+ } ) ;
208+ }
209+
200210function _indentedEltHtml ( $elt , i , filterFnOpt ) {
201211 let lines = $elt . html ( ) . split ( '\n' ) ;
202212 if ( filterFnOpt ) lines = lines . filter ( filterFnOpt ) ;
203213 const indent = ' ' . substring ( 0 , i ) ;
204214 return lines . map ( ( line ) => `${ indent } | ${ line } ` ) . join ( '\n' ) ;
205215}
206216
207- function apiEntryJadeTemplate ( baseHrefDepth , $breadcrumbs , $mainDiv ) {
217+ function apiEntryJadeTemplate ( $ , baseHrefDepth , $breadcrumbs , $mainDiv ) {
208218 const baseHref = path . join ( ...Array ( baseHrefDepth ) . fill ( '..' ) ) ;
209219 // TODO/investigate: for some reason $breadcrumbs.html() is missing the <ol></ol>. We add it back in the template below.
220+ _adjustAnchorHref ( $ , $breadcrumbs , baseHref ) ;
210221 const breadcrumbs = _indentedEltHtml ( $breadcrumbs , 6 , ( line ) => ! line . match ( / ^ \s * $ / ) ) ;
222+ _adjustAnchorHref ( $ , $mainDiv , baseHref ) ;
211223 const mainDivHtml = _indentedEltHtml ( $mainDiv , 4 ) ;
212224 // WARNING: since the following is Jade, indentation is significant.
213225 const result = `
@@ -217,8 +229,8 @@ include ${baseHref}/../_util-fns
217229
218230block head-extra
219231 // generated Dart API page template: head-extra
220- //- <base> is required because all the links in dartdoc generated pages are "pseudo-absolute"
221- base(href="${ baseHref } ")
232+ //- <base> is no longer required
233+ //- base(href="${ baseHref } ")
222234
223235block breadcrumbs
224236 // generated Dart API page template: breadcrumbs
0 commit comments