diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 24a5aae..456efea 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -43,7 +43,8 @@ jobs: run: pnpm build env: NODE_ENV: production - BASE_URL: ${{ github.event.repository.name }} + BASE_PATH: ${{ github.event.repository.name }} + BASE_URL: arthur.run - name: Upload artifact uses: actions/upload-pages-artifact@v2 diff --git a/astro.config.mjs b/astro.config.mjs index a266d42..f9a7971 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -5,12 +5,12 @@ import sitemap from '@astrojs/sitemap'; import compress from 'astro-compress'; import robotsTxt from 'astro-robots-txt'; import AstroPWA from '@vite-pwa/astro'; -import { BasePath, Url } from './src/utils/url'; +import { BasePath, PUBLIC_URL } from './src/utils/url'; // https://astro.build/config export default defineConfig({ - site: Url, - base: BasePath, + site: PUBLIC_URL.toString(), + base: `${PUBLIC_URL.pathname}/`, output: 'static', build: { format: 'file' diff --git a/src/pages/404.astro b/src/pages/404.astro index a0493ca..71a9faf 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -1,12 +1,12 @@ --- -import { Url } from "../utils/url"; +import { PUBLIC_URL } from "../utils/url"; --- -Redirecting to {Url} +Redirecting to {PUBLIC_URL} - \ No newline at end of file + \ No newline at end of file diff --git a/src/utils/seo.ts b/src/utils/seo.ts index 33621ec..8ecab51 100644 --- a/src/utils/seo.ts +++ b/src/utils/seo.ts @@ -1,6 +1,6 @@ import type { Props } from 'astro-seo'; import { pwaAssetsHead } from 'virtual:pwa-assets/head'; -import { Url } from './url'; +import { PUBLIC_URL } from './url'; export const SeoProps: Props = { title: 'Risk Dice Roller', @@ -8,7 +8,7 @@ export const SeoProps: Props = { 'A simple dice roller for the board game Risk. Roll the dice and see the results of your attack or defense.', openGraph: { basic: { - image: `${Url}/android-chrome-512.png`, + image: `${PUBLIC_URL}/android-chrome-512.png`, type: 'website', title: 'Risk Dice Roller' } diff --git a/src/utils/url.ts b/src/utils/url.ts index e7c1b77..53429c4 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -1,3 +1,20 @@ -export const Domain = 'https://arthur.run'; -export const BasePath = process.env.BASE_URL || 'risk-dice'; -export const Url = `${Domain}/${BasePath}`; +function replaceSlashes(url?: string) { + if (!url) { + return undefined; + } + + if (url.startsWith('/')) { + url = url.replace('/', ''); + } + + if (url.endsWith('/')) { + url = url.replace('/', ''); + } + + return url; +} + +const basePath = replaceSlashes(process.env.BASE_PATH) || 'risk-dice'; +const domain = replaceSlashes(process.env.BASE_URL) || 'https://localhost:4321'; + +export const PUBLIC_URL = new URL(basePath, domain);