11import { createApp , ref } from 'vue' ;
22import { toggleElem } from '../utils/dom.ts' ;
3+ import { pathEscapeSegments , pathUnescapeSegments } from '../utils/url.ts' ;
34import { GET , PUT } from '../modules/fetch.ts' ;
45import ViewFileTree from '../components/ViewFileTree.vue' ;
56
@@ -28,7 +29,7 @@ function childrenLoader(sidebarEl: HTMLElement) {
2829 const fileTree = sidebarEl . querySelector ( '#view-file-tree' ) ;
2930 const apiBaseUrl = fileTree . getAttribute ( 'data-api-base-url' ) ;
3031 const refTypeNameSubURL = fileTree . getAttribute ( 'data-current-ref-type-name-sub-url' ) ;
31- const response = await GET ( encodeURI ( `${ apiBaseUrl } /tree/${ refTypeNameSubURL } /${ path ?? '' } ?recursive=${ recursive ?? false } ` ) ) ;
32+ const response = await GET ( `${ apiBaseUrl } /tree/${ refTypeNameSubURL } /${ pathEscapeSegments ( path ?? '' ) } ?recursive=${ recursive ?? false } ` ) ;
3233 const json = await response . json ( ) ;
3334 if ( json instanceof Array ) {
3435 return json . map ( ( i ) => ( {
@@ -81,7 +82,7 @@ export async function initViewFileTreeSidebar() {
8182
8283 fileTree . classList . remove ( 'is-loading' ) ;
8384 const fileTreeView = createApp ( ViewFileTree , { files, selectedItem, loadChildren : childrenLoader ( sidebarEl ) , loadContent : ( path : string ) => {
84- window . history . pushState ( null , null , encodeURI ( `${ baseUrl } /src${ refString } /${ path } ` ) ) ;
85+ window . history . pushState ( null , null , `${ baseUrl } /src${ refString } /${ pathEscapeSegments ( path ) } ` ) ;
8586 selectedItem . value = path ;
8687 loadContent ( sidebarEl ) ;
8788 } } ) ;
@@ -94,6 +95,6 @@ export async function initViewFileTreeSidebar() {
9495}
9596
9697function getSelectedPath ( ref : string ) {
97- const path = decodeURI ( new URL ( window . location . href ) . pathname ) ;
98+ const path = pathUnescapeSegments ( new URL ( window . location . href ) . pathname ) ;
9899 return path . substring ( path . indexOf ( ref ) + ref . length + 1 ) ;
99100}
0 commit comments