@@ -29,9 +29,11 @@ async function toggleSidebar(visibility) {
2929}
3030
3131async function loadChildren ( item , recursive ?: boolean ) {
32- const el = document . querySelector ( '#view-file-tree' ) ;
33- const apiBaseUrl = el . getAttribute ( 'data-api-base-url' ) ;
34- const response = await GET ( `${ apiBaseUrl } /tree/${ item ? item . path : '' } ?ref=&recursive=${ recursive ?? false } ` ) ;
32+ const fileTree = document . querySelector ( '#view-file-tree' ) ;
33+ const apiBaseUrl = fileTree . getAttribute ( 'data-api-base-url' ) ;
34+ const refType = fileTree . getAttribute ( 'data-current-ref-type' ) ;
35+ const refName = fileTree . getAttribute ( 'data-current-ref-short-name' ) ;
36+ const response = await GET ( `${ apiBaseUrl } /tree/${ item ? item . path : '' } ?ref=${ refType } /${ refName } &recursive=${ recursive ?? false } ` ) ;
3537 const json = await response . json ( ) ;
3638 if ( json instanceof Array ) {
3739 return json . map ( ( i ) => ( {
@@ -64,15 +66,18 @@ export async function initViewFileTreeSidebar() {
6466 } ) ;
6567
6668 const fileTree = document . querySelector ( '#view-file-tree' ) ;
69+ const baseUrl = fileTree . getAttribute ( 'data-api-base-url' ) ;
6770 const treePath = fileTree . getAttribute ( 'data-tree-path' ) ;
68- const basePath = window . location . href . replace ( treePath , '' ) ;
71+ const refType = fileTree . getAttribute ( 'data-current-ref-type' ) ;
72+ const refName = fileTree . getAttribute ( 'data-current-ref-short-name' ) ;
73+
6974 const selectedItem = ref ( treePath ) ;
7075
7176 const files = await loadChildren ( { path : treePath } , true ) ;
7277
7378 fileTree . classList . remove ( 'is-loading' ) ;
7479 const fileTreeView = createApp ( ViewFileTree , { files, selectedItem, loadChildren, loadContent : ( item ) => {
75- window . history . pushState ( null , null , `${ basePath } ${ item . path } ` ) ;
80+ window . history . pushState ( null , null , `${ baseUrl } /src/ ${ refType } / ${ refName } / ${ item . path } ` ) ;
7681 selectedItem . value = item . path ;
7782 loadContent ( item ) ;
7883 } } ) ;
0 commit comments