diff --git a/helpers/url.js b/helpers/url.js index e85a4fc..f318afc 100644 --- a/helpers/url.js +++ b/helpers/url.js @@ -37,3 +37,15 @@ export function getSiteUrl () { throw new Error('Could not find site URL') } + +export function getPathPartsFromAstroRequest ( AstroRequest ) { + // Parse the request url + const requestUrl = new URL( AstroRequest.url ) + + const pathParts = requestUrl.pathname + .replace(/^\/+/, '') // Trim slashes from the beginning + .replace(/\/+$/, '') // Trim slashes from the end + .split('/') + + return pathParts +}