Skip to content

Commit 96486bb

Browse files
authored
Merge pull request #59 from mapachurro/fix-relative-paths
Attempting to fix a relative path issue that mysteriously broke
2 parents b5b422f + b58e864 commit 96486bb

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/js/index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,37 @@ if (typeof document !== "undefined") {
1212
// Fetch directoryContents.json for use in other scripts
1313
const locale = document.documentElement.lang;
1414
const localeSlug = await convertLocaleFormat(locale, "fourLetterDash", "slug");
15-
const jsonFilePath = `../${localeSlug}/directoryContents.json`;
16-
15+
16+
// Use a path relative to the current page instead of going up a directory
17+
// This handles both development and production environments better
18+
const jsonFilePath = `./${localeSlug}/directoryContents.json`;
19+
1720
let directoryContents = [];
1821
try {
22+
console.log(`Attempting to load directory contents from: ${jsonFilePath}`);
1923
const response = await fetch(jsonFilePath);
2024
if (!response.ok) {
21-
throw new Error(`Failed to load index file: ${response.statusText}`);
25+
throw new Error(`Failed to load index file: ${response.statusText} (${response.status})`);
2226
}
2327
directoryContents = await response.json();
24-
console.log("Directory contents loaded", directoryContents);
28+
console.log("Directory contents loaded successfully", directoryContents);
2529
} catch (error) {
2630
console.error("Error loading directory index:", error);
31+
32+
// Fallback attempt with alternative path
33+
try {
34+
console.log("Trying fallback path...");
35+
const fallbackPath = `/${localeSlug}/directoryContents.json`;
36+
console.log(`Attempting fallback: ${fallbackPath}`);
37+
const fallbackResponse = await fetch(fallbackPath);
38+
if (!fallbackResponse.ok) {
39+
throw new Error(`Fallback also failed: ${fallbackResponse.statusText}`);
40+
}
41+
directoryContents = await fallbackResponse.json();
42+
console.log("Directory contents loaded from fallback path", directoryContents);
43+
} catch (fallbackError) {
44+
console.error("Fallback attempt also failed:", fallbackError);
45+
}
2746
}
2847

2948
// Initialize Search

0 commit comments

Comments
 (0)