mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-21 06:54:08 -07:00
Return object for getPathPartsFromAstroRequest
This commit is contained in:
parent
5dbbca4610
commit
5d6e4954da
3 changed files with 23 additions and 8 deletions
|
|
@ -74,5 +74,18 @@ export function getPartPartsFromUrl ( urlString ) {
|
||||||
export function getPathPartsFromAstroRequest ( AstroRequest ) {
|
export function getPathPartsFromAstroRequest ( AstroRequest ) {
|
||||||
// Parse the request url
|
// 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,10 @@ if ( redirectResponse !== null ) {
|
||||||
// Get type and slug from the request path
|
// Get type and slug from the request path
|
||||||
// so that we don't have extra parts for
|
// so that we don't have extra parts for
|
||||||
// urls like /:type/:slug/benchmarks
|
// urls like /:type/:slug/benchmarks
|
||||||
const [
|
const {
|
||||||
,
|
|
||||||
pathSlug,
|
pathSlug,
|
||||||
subSlug = null
|
subSlug = null
|
||||||
] = getPathPartsFromAstroRequest( Astro.request )
|
} = getPathPartsFromAstroRequest( Astro.request )
|
||||||
|
|
||||||
const isBenchmarkPage = subSlug === 'benchmarks'
|
const isBenchmarkPage = subSlug === 'benchmarks'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,13 @@ import Listing from '../../components/default-listing.astro'
|
||||||
// Get type and slug from the request path
|
// Get type and slug from the request path
|
||||||
// so that we don't have extra parts for
|
// so that we don't have extra parts for
|
||||||
// urls like /:type/:slug/benchmarks
|
// 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
|
// Use request path parts to set api url path
|
||||||
// apiUrl.pathname = `/api/${ pathType }/${ pathSlug }.json`
|
// apiUrl.pathname = `/api/${ pathType }/${ pathSlug }.json`
|
||||||
|
|
@ -65,5 +68,5 @@ if ( redirectResponse !== null ) {
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
||||||
Kind: { JSON.stringify( pathParts ) }
|
Kind: { JSON.stringify( pathname ) }
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue