@@ -77,24 +77,26 @@ document.addEventListener('DOMContentLoaded', () => {
7777 //==============================================================================
7878 // Parses the URL on load and populates the file explorer state
7979 async function handleInitialUrl ( ) {
80- // Check if redirected from 404.html
81- const redirectPath = sessionStorage . getItem ( 'redirectPath' ) ;
82- if ( redirectPath ) {
83- sessionStorage . removeItem ( 'redirectPath' ) ;
84-
85- // Update the URL bar back to the correct virtual path without reloading the page.
86- history . replaceState ( null , '' , redirectPath ) ;
80+ const redirectUrl = sessionStorage . getItem ( 'redirect' ) ;
81+ if ( redirectUrl ) {
82+ sessionStorage . removeItem ( 'redirect' ) ;
83+ history . replaceState ( null , '' , redirectUrl ) ;
8784 }
8885
89- // Now, proceed with the (potentially updated) path from the URL bar
86+ // Proceed with the path from the URL bar
9087 const path = window . location . pathname ;
9188 const params = new URLSearchParams ( window . location . search ) ;
9289 const previewFile = params . get ( 'preview' ) ;
9390
94- const match = path . match ( / \/ f e \/ ( [ ^ / ] + ) \/ ( [ ^ / ] + ) \/ ? ( .* ) / ) ;
91+ // This regex needs to account for potential repository names in the path on GitHub Pages
92+ const pathSegments = path . split ( '/' ) . filter ( Boolean ) ;
93+ const feIndex = pathSegments . indexOf ( 'fe' ) ;
94+
95+ if ( feIndex > - 1 && pathSegments . length >= feIndex + 3 ) {
96+ const owner = pathSegments [ feIndex + 1 ] ;
97+ const repo = pathSegments [ feIndex + 2 ] ;
98+ const filePath = pathSegments . slice ( feIndex + 3 ) . join ( '/' ) ;
9599
96- if ( match ) {
97- const [ , owner , repo , filePath ] = match ;
98100 DOM . ownerInput . value = owner ;
99101 DOM . repoInput . value = repo ;
100102 state . owner = owner ;
@@ -107,10 +109,11 @@ document.addEventListener('DOMContentLoaded', () => {
107109
108110 if ( previewFile ) {
109111 // Find the file in the current listing and open its preview
110- const fileItemElement = DOM . fileListingContainer . querySelector ( `[data-path="${ filePath ? filePath + '/' : '' } ${ previewFile } "]` ) ;
112+ const fullItemPath = ( filePath ? filePath + '/' : '' ) + previewFile ;
113+ const fileItemElement = DOM . fileListingContainer . querySelector ( `[data-path="${ fullItemPath } "]` ) ;
111114 if ( fileItemElement ) {
112115 const item = {
113- path : ` ${ filePath ? filePath + '/' : '' } ${ previewFile } ` ,
116+ path : fullItemPath ,
114117 name : previewFile ,
115118 type : 'file' ,
116119 } ;
0 commit comments