mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add getPartPartsFromUrl function
This commit is contained in:
parent
93afef5f62
commit
b188d3cd72
1 changed files with 11 additions and 4 deletions
|
|
@ -38,14 +38,21 @@ export function getSiteUrl () {
|
||||||
throw new Error('Could not find site URL')
|
throw new Error('Could not find site URL')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPathPartsFromAstroRequest ( AstroRequest ) {
|
export function getPartPartsFromUrl ( urlString ) {
|
||||||
// Parse the request url
|
if ( typeof urlString !== 'string' ) throw new Error('urlString must be a string')
|
||||||
const requestUrl = new URL( AstroRequest.url )
|
|
||||||
|
|
||||||
const pathParts = requestUrl.pathname
|
const url = new URL( urlString )
|
||||||
|
|
||||||
|
const pathParts = url.pathname
|
||||||
.replace(/^\/+/, '') // Trim slashes from the beginning
|
.replace(/^\/+/, '') // Trim slashes from the beginning
|
||||||
.replace(/\/+$/, '') // Trim slashes from the end
|
.replace(/\/+$/, '') // Trim slashes from the end
|
||||||
.split('/')
|
.split('/')
|
||||||
|
|
||||||
return pathParts
|
return pathParts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPathPartsFromAstroRequest ( AstroRequest ) {
|
||||||
|
// Parse the request url
|
||||||
|
|
||||||
|
return getPartPartsFromUrl ( AstroRequest.url )
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue