Skip to content

Commit 84b1eaf

Browse files
committed
feat: extensionless URL resolution in preview server
Links like <a href="about"> now resolve to about.html or about/index.html Fixes: Acode-Foundation#1739
1 parent 56c2358 commit 84b1eaf

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/lib/run.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,33 @@ async function run(
256256
file = activeFile;
257257
}
258258

259+
// Handle extensionless URLs (e.g., "about" -> "about.html" or "about/index.html")
260+
if (!ext && pathName) {
261+
// Try path.html first
262+
const htmlUrl = Url.join(pathName, reqPath + ".html");
263+
const htmlFile = editorManager.getFile(htmlUrl, "uri");
264+
if (htmlFile?.loaded && htmlFile.isUnsaved) {
265+
sendHTML(htmlFile.session?.getValue(), reqId);
266+
return;
267+
}
268+
const htmlFs = fsOperation(htmlUrl);
269+
if (await htmlFs.exists()) {
270+
sendFileContent(htmlUrl, reqId, MIMETYPE_HTML);
271+
return;
272+
}
273+
274+
// Try path/index.html
275+
const indexUrl = Url.join(pathName, reqPath, "index.html");
276+
const indexFs = fsOperation(indexUrl);
277+
if (await indexFs.exists()) {
278+
sendFileContent(indexUrl, reqId, MIMETYPE_HTML);
279+
return;
280+
}
281+
282+
error(reqId);
283+
return;
284+
}
285+
259286
switch (ext) {
260287
case ".htm":
261288
case ".html":

0 commit comments

Comments
 (0)