@@ -285,12 +285,30 @@ <h2>{{title}}</h2>
285285 submitButton . value = 'Sending...' ;
286286
287287 try {
288- // Get the base path for GitHub Pages
289- const basePath = location . pathname . endsWith ( '/' ) ? location . pathname : location . pathname + '/' ;
290- console . log ( 'Loading config from:' , basePath + 'config.json' ) ;
288+ // Get the base URL for config loading
289+ const getConfigPath = ( ) => {
290+ // Check if we're on GitHub Pages
291+ if ( window . location . hostname . endsWith ( 'github.io' ) ) {
292+ const pathSegments = window . location . pathname . split ( '/' ) ;
293+ // Remove empty segments and get repo name
294+ const repoName = pathSegments . filter ( s => s ) [ 0 ] ;
295+ return `/${ repoName } /config.json` ;
296+ }
297+
298+ // For custom domain or local development
299+ const currentPath = window . location . pathname ;
300+ const configPath = currentPath . endsWith ( '/' )
301+ ? currentPath + 'config.json'
302+ : currentPath . substring ( 0 , currentPath . lastIndexOf ( '/' ) + 1 ) + 'config.json' ;
303+
304+ return configPath ;
305+ } ;
306+
307+ const configPath = getConfigPath ( ) ;
308+ console . log ( 'Loading config from:' , configPath ) ;
291309
292310 // Load webhook URL from config file
293- const configResponse = await fetch ( basePath + 'config.json' ) ;
311+ const configResponse = await fetch ( configPath ) ;
294312 if ( ! configResponse . ok ) {
295313 throw new Error ( `Failed to load configuration. Please try again later.` ) ;
296314 }
0 commit comments