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')
|
||||
}
|
||||
|
||||
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 )
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue