1
0
silverbullet/plug-api/lib/resolve.ts
2023-07-29 23:41:37 +02:00

21 lines
546 B
TypeScript

export function resolvePath(
currentPage: string,
pathToResolve: string,
fullUrl = false,
): string {
if (currentPage.startsWith("!") && !pathToResolve.startsWith("!")) {
let domainPart = currentPage.split("/")[0];
if (fullUrl) {
domainPart = domainPart.substring(1);
if (domainPart.startsWith("localhost")) {
domainPart = "http://" + domainPart;
} else {
domainPart = "https://" + domainPart;
}
}
return `${domainPart}/${pathToResolve}`;
} else {
return pathToResolve;
}
}