From b188d3cd722ff9f6a4bc363018e43870589176d1 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Thu, 5 May 2022 13:47:23 -0500 Subject: [PATCH] Add getPartPartsFromUrl function --- helpers/url.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/helpers/url.js b/helpers/url.js index f318afc..43a3c5b 100644 --- a/helpers/url.js +++ b/helpers/url.js @@ -38,14 +38,21 @@ 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 ) +export function getPartPartsFromUrl ( urlString ) { + if ( typeof urlString !== 'string' ) throw new Error('urlString must be a string') - const pathParts = requestUrl.pathname + const url = new URL( urlString ) + + const pathParts = url.pathname .replace(/^\/+/, '') // Trim slashes from the beginning .replace(/\/+$/, '') // Trim slashes from the end .split('/') return pathParts } + +export function getPathPartsFromAstroRequest ( AstroRequest ) { + // Parse the request url + + return getPartPartsFromUrl ( AstroRequest.url ) +}