Skip to content

Commit 4af8e47

Browse files
committed
path fix
1 parent 773d7de commit 4af8e47

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

.vitepress/config.mjs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,27 @@ function buildSidebar() {
8484
// skip root index (home) at top level
8585
if (relPath === '' && name === 'index') continue;
8686

87-
// compute link
87+
// compute link (encode each segment to avoid spaces causing Invalid URL)
8888
let link;
8989
if (name === 'index') {
9090
// directory index becomes the path to folder
91-
link = `/${relPath}/`.replace(/\\/g, '/');
91+
// encode each part of relPath separately
92+
if (relPath) {
93+
const parts = relPath.split('/').map(encodeURIComponent);
94+
link = `/${parts.join('/')}/`;
95+
} else {
96+
link = `/`;
97+
}
9298
} else {
93-
link = `/${relPath}/${name}`.replace(/\\/g, '/');
99+
if (relPath) {
100+
const parts = relPath.split('/').map(encodeURIComponent);
101+
parts.push(encodeURIComponent(name));
102+
link = `/${parts.join('/')}`;
103+
} else {
104+
link = `/${encodeURIComponent(name)}`;
105+
}
94106
}
107+
link = link.replace(/\\/g, '/');
95108
items.push({ text: name, link });
96109
}
97110

0 commit comments

Comments
 (0)