Created
January 15, 2024 14:17
-
-
Save Mearman/5627fd9ab9e273eb1acaf02ece737f27 to your computer and use it in GitHub Desktop.
Revisions
-
Mearman created this gist
Jan 15, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ <!DOCTYPE html> <html> <head> <title>Page Loading...</title> <script> function fetchAndReplaceContent(basePath, additionalSegments) { if (additionalSegments.length === 0) { document.body.innerHTML = '<h1>Page not found.</h1>'; return; } var projectPath = basePath + additionalSegments.join('/') + '/index.html'; fetch(projectPath).then(response => { if (response.ok) { return response.text(); } else { // Try the next level up additionalSegments.pop(); fetchAndReplaceContent(basePath, additionalSegments); } }).then(html => { if (html) { document.open(); document.write(html); document.close(); } }).catch(error => { console.error('Error loading content:', error); document.body.innerHTML = '<h1>Error loading page.</h1>'; }); } document.addEventListener('DOMContentLoaded', function () { var basePath = '/web/'; var currentPath = window.location.pathname; if (currentPath.startsWith(basePath)) { var pathSegments = currentPath.split('/').filter(Boolean); var additionalSegments = pathSegments.slice(1); // Exclude the base path segment fetchAndReplaceContent(basePath, additionalSegments); } else { document.body.innerHTML = '<h1>Page not found.</h1>'; } }); </script> </head> <body> <h1>Loading...</h1> </body> </html>