More fixes related to #363

This commit is contained in:
Zef Hemel
2023-12-19 17:55:11 +01:00
parent a5c7405a35
commit 30436d97ea
9 changed files with 70 additions and 31 deletions
+21
View File
@@ -16,7 +16,24 @@ export function resolvePath(
}
}
export function resolveAttachmentPath(
currentPage: string,
pathToResolve: string,
): string {
const folder = folderName(currentPage);
if (folder && !pathToResolve.startsWith("/")) {
pathToResolve = folder + "/" + pathToResolve;
}
if (pathToResolve.startsWith("/")) {
pathToResolve = pathToResolve.slice(1);
}
return federatedPathToUrl(resolvePath(currentPage, pathToResolve));
}
export function federatedPathToUrl(path: string): string {
if (!path.startsWith("!")) {
return path;
}
path = path.substring(1);
if (path.startsWith("localhost")) {
path = "http://" + path;
@@ -101,3 +118,7 @@ export function cleanPageRef(pageRef: string) {
return pageRef;
}
}
export function folderName(path: string) {
return path.split("/").slice(0, -1).join("/");
}