Skip to content

Commit da7a73c

Browse files
committed
now?
1 parent 9d1a027 commit da7a73c

2 files changed

Lines changed: 18 additions & 23 deletions

File tree

404.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@
55
<meta charset="UTF-8">
66
<title>Live2D Viewer - Loading...</title>
77
<script type="text/javascript">
8-
(function () {
9-
const pathname = window.location.pathname;
10-
const search = window.location.search;
11-
const basePath = pathname.substring(0, pathname.lastIndexOf('/') + 1);
12-
const targetUrl = window.location.origin + basePath;
13-
if (!pathname.endsWith('/404.html')) {
14-
sessionStorage.setItem('redirectPath', pathname + search);
15-
}
16-
window.location.replace(targetUrl);
17-
})();
8+
sessionStorage.setItem('redirect', location.href);
9+
window.location.replace(document.baseURI);
1810
</script>
1911
</head>
2012

js/repoexplorer.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/\/fe\/([^/]+)\/([^/]+)\/?(.*)/);
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

Comments
 (0)