Skip to content

Commit

Permalink
fix: seo and assets base path
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Sep 25, 2024
1 parent 41eaeb9 commit a22142e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
import { Url } from "../utils/url";
import { PUBLIC_URL } from "../utils/url";
---

<!doctype html>
<meta charset="utf-8" />
<title>Redirecting to {Url}</title>
<title>Redirecting to {PUBLIC_URL}</title>
<meta
http-equiv="refresh"
content={`0; URL=${Url}`}
content={`0; URL=${PUBLIC_URL}`}
/>
<link rel="canonical" href={Url} />
<link rel="canonical" href={PUBLIC_URL} />
4 changes: 2 additions & 2 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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',
description:
'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'
}
Expand Down
23 changes: 20 additions & 3 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit a22142e

Please sign in to comment.