diff --git a/helpers/url.js b/helpers/url.js index e026426..42ce818 100644 --- a/helpers/url.js +++ b/helpers/url.js @@ -74,5 +74,18 @@ export function getPartPartsFromUrl ( urlString ) { export function getPathPartsFromAstroRequest ( AstroRequest ) { // Parse the request url - return getPartPartsFromUrl ( AstroRequest.url ) + const url = new URL( AstroRequest.url, 'https://doesitarm.com' ) + + const [ + routeType, + pathSlug, + subSlug = null + ] = getPartPartsFromUrl ( AstroRequest.url ) + + return { + pathname: url.pathname, + routeType, + pathSlug, + subSlug + } } diff --git a/src/pages/app/[...appPath].astro b/src/pages/app/[...appPath].astro index b15584b..332cd0e 100644 --- a/src/pages/app/[...appPath].astro +++ b/src/pages/app/[...appPath].astro @@ -25,11 +25,10 @@ if ( redirectResponse !== null ) { // Get type and slug from the request path // so that we don't have extra parts for // urls like /:type/:slug/benchmarks -const [ - , +const { pathSlug, subSlug = null -] = getPathPartsFromAstroRequest( Astro.request ) + } = getPathPartsFromAstroRequest( Astro.request ) const isBenchmarkPage = subSlug === 'benchmarks' diff --git a/src/pages/kind/[...kindPath].astro b/src/pages/kind/[...kindPath].astro index 4495a69..d3b4a8b 100644 --- a/src/pages/kind/[...kindPath].astro +++ b/src/pages/kind/[...kindPath].astro @@ -19,10 +19,13 @@ import Listing from '../../components/default-listing.astro' // Get type and slug from the request path // so that we don't have extra parts for // urls like /:type/:slug/benchmarks -const pathParts = getPathPartsFromAstroRequest( Astro.request ) +const { + pathname, + // pathSlug, + // subSlug = null + } = getPathPartsFromAstroRequest( Astro.request ) + -// Create an empty API URL -const apiUrl = new URL( import.meta.env.PUBLIC_API_DOMAIN ) // Use request path parts to set api url path // apiUrl.pathname = `/api/${ pathType }/${ pathSlug }.json` @@ -65,5 +68,5 @@ if ( redirectResponse !== null ) { }} > - Kind: { JSON.stringify( pathParts ) } + Kind: { JSON.stringify( pathname ) }