File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -114,13 +114,20 @@ function copyImages (src, dest) {
114114 . pipe ( map ( ( file , enc , next ) => next ( ) ) )
115115}
116116
117- function relativize ( to , { data } ) {
117+ function relativize ( to , { data : { root } } ) {
118118 if ( ! to ) return '#'
119119 if ( to . charAt ( ) !== '/' ) return to
120- const from = data . root . page . url
120+ const from = root . page . url
121+ if ( ! from ) return ( root . site . path || '' ) + to
122+ let hash = ''
121123 const hashIdx = to . indexOf ( '#' )
122- if ( ~ hashIdx && to . substr ( 0 , hashIdx ) === from ) return to . substr ( hashIdx )
123- return to . substr ( 1 )
124+ if ( ~ hashIdx ) {
125+ hash = to . substr ( hashIdx )
126+ to = to . substr ( 0 , hashIdx )
127+ }
128+ return to === from
129+ ? hash || ( to . charAt ( to . length - 1 ) === '/' ? './' : path . basename ( to ) )
130+ : ( path . relative ( path . dirname ( from + '.' ) , to ) || '.' ) + ( to . charAt ( to . length - 1 ) === '/' ? '/' + hash : hash )
124131}
125132
126133function resolvePage ( spec , context = { } ) {
You can’t perform that action at this time.
0 commit comments