Add getPathPartsFromAstroRequest helper

This commit is contained in:
Sam Carlton 2022-05-03 16:02:40 -05:00
parent 1df930059e
commit e34e661f86

View file

@ -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
}