From e34e661f862f630d73242df515bc00c04afaa266 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Tue, 3 May 2022 16:02:40 -0500 Subject: [PATCH] Add getPathPartsFromAstroRequest helper --- helpers/url.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 +}