mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add getSiteUrl helper
This commit is contained in:
parent
0a28d0e393
commit
44c6a82957
1 changed files with 30 additions and 0 deletions
30
helpers/get-site-url.js
Normal file
30
helpers/get-site-url.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
export function getSiteUrl () {
|
||||
|
||||
// console.log( 'import.meta.site', import.meta.env )
|
||||
|
||||
// Try process.env.URL
|
||||
if ( typeof process.env.URL !== 'undefined' ) {
|
||||
console.log('Has env.URL')
|
||||
return process.env.URL
|
||||
}
|
||||
|
||||
// Try Astro.site.origin
|
||||
if ( typeof Astro !== 'undefined' ) {
|
||||
console.log('Has Astro')
|
||||
return Astro.site.origin
|
||||
}
|
||||
|
||||
// Try URL
|
||||
if ( typeof import.meta.env.URL !== 'undefined' ) {
|
||||
console.log('Has URL')
|
||||
return import.meta.env.URL
|
||||
}
|
||||
|
||||
// Try PUBLIC_URL
|
||||
if ( typeof import.meta.env.PUBLIC_URL !== 'undefined' ) {
|
||||
console.log('Has PUBLIC_URL')
|
||||
return import.meta.env.PUBLIC_URL
|
||||
}
|
||||
|
||||
throw new Error('Could not find site URL')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue