File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 11export default class RunButtonPlugin {
2+ ORIGIN = globalThis . location . origin ;
23 PATH = globalThis . location . pathname ;
3- BASE_URL = document . querySelector ( 'base' ) ?. getAttribute ( 'href' ) || globalThis . location . origin ;
4+ BASE_URL = document . querySelector ( 'base' ) ?. getAttribute ( 'href' ) ;
45 RELATIVE_PATH = this . PATH . replace ( this . BASE_URL , '' ) ;
56 PLAYGROUND_URL = 'playground' ;
67
@@ -21,8 +22,9 @@ export default class RunButtonPlugin {
2122 const urlParams = new URLSearchParams ( ) ;
2223 urlParams . set ( 'code' , text ) ;
2324 const hash = urlParams . toString ( ) ;
24- const version = this . RELATIVE_PATH . startsWith ( 'docs/' ) ? '' : `${ this . RELATIVE_PATH . split ( '/' ) [ 0 ] } /` ;
25- globalThis . location . href = `${ this . BASE_URL } ${ version } ${ this . PLAYGROUND_URL } #${ hash } ` ;
25+ const hasVersion = this . RELATIVE_PATH !== '' && ! this . RELATIVE_PATH . startsWith ( 'docs/' ) && ! this . RELATIVE_PATH . startsWith ( 'index' ) ;
26+ const version = hasVersion ? `${ this . RELATIVE_PATH . split ( '/' ) [ 0 ] } /` : '' ;
27+ globalThis . location . href = `${ this . ORIGIN } ${ this . BASE_URL } ${ version } ${ this . PLAYGROUND_URL } #${ hash } ` ;
2628 } ) ;
2729 const wrapper = document . createElement ( 'div' ) ;
2830 wrapper . classList . add ( 'hljs-run' ) ;
You can’t perform that action at this time.
0 commit comments