Skip to content

Commit cde67c0

Browse files
committed
Fix: Properly encode local content paths for GitHub Pages
- Apply URL encoding to local content paths so special characters are handled correctly - GitHub Pages requires URL encoding for paths with spaces and special characters - Removed unnecessary fallback logic since proper encoding fixes the issue
1 parent 0351d33 commit cde67c0

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

docs/app.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ function encodePath(path) {
4040
}
4141

4242
function fileUrlForPath(path) {
43+
const encoded = encodePath(path);
4344
if (state.useLocalContent) {
44-
// For local content, don't encode - the files are already in the correct structure
45-
return `content/${path}`;
45+
// For local content, use encoded path since GitHub Pages needs URL encoding
46+
return `content/${encoded}`;
4647
}
47-
// For GitHub raw content, encode the path properly
48-
const encoded = encodePath(path);
48+
// For GitHub raw content, use encoded path
4949
return `https://raw.githubusercontent.com/${state.repoOwner}/${state.repoName}/${state.branch}/${encoded}`;
5050
}
5151

@@ -113,16 +113,7 @@ async function loadFile(path, meta = {}) {
113113
codeBlock.className = languageClass ? `language-${languageClass}` : "";
114114

115115
try {
116-
let url = fileUrlForPath(path);
117-
let response = await fetch(url);
118-
119-
// If local content fails, fall back to GitHub raw content
120-
if (!response.ok && state.useLocalContent) {
121-
const encoded = encodePath(path);
122-
url = `https://raw.githubusercontent.com/${state.repoOwner}/${state.repoName}/${state.branch}/${encoded}`;
123-
response = await fetch(url);
124-
}
125-
116+
const response = await fetch(fileUrlForPath(path));
126117
if (!response.ok) {
127118
throw new Error(`Failed to fetch ${path}`);
128119
}

0 commit comments

Comments
 (0)