use URI.resolve

This commit is contained in:
Dallin Romney 2025-03-03 16:08:15 -08:00
parent ceede791bd
commit 892f89e0e2

View file

@ -116,19 +116,30 @@ export function getLastNUriRelativePathParts(
}
export function joinPathsToUri(uri: string, ...pathSegments: string[]) {
const components = URI.parse(uri);
let baseUri = uri;
if (baseUri.at(-1) !== "/") {
baseUri += "/";
}
const segments = pathSegments.map((segment) => pathToUriPathSegment(segment));
components.path = `${components.path}/${segments.join("/")}`;
return URI.serialize(components);
return URI.resolve(baseUri, segments.join("/"));
}
// const components = URI.parse(uri);
// return URI.serialize(components);
// components.path = `${components.path}/${segments.join("/")}`;
export function joinEncodedUriPathSegmentToUri(
uri: string,
pathSegment: string,
) {
const components = URI.parse(uri);
components.path = `${components.path}/${pathSegment}`;
return URI.serialize(components);
let baseUri = uri;
if (baseUri.at(-1) !== "/") {
baseUri += "/";
}
return URI.resolve(baseUri, pathSegment);
// const components = URI.parse(uri);
// components.path = `${components.path}/${pathSegment}`;
// return URI.serialize(components);
}
export function getShortestUniqueRelativeUriPaths(