running-tools

A collection of tools for runners and their coaches
git clone https://git.ashermorgan.net/running-tools/
Log | Files | Refs | README

commit 780ebf5dd8c9bf2ee10ead9acf6c7c6a2cbee85b
parent 281a018f690d1e8415c766c65ae3ffd1f933e439
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Fri, 30 May 2025 18:57:33 -0700

Refactor vite build variables

Add internal VITE_DESCRIPTION variable and use DOMAIN environment
variable to set OpenGraph URLs instead of VITE_API_DOMAIN.

Diffstat:
D.env | 2--
M404.html | 2+-
MREADME.md | 2+-
Mindex.html | 8++++----
Mvite.config.js | 20+++++++++++++-------
5 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/.env b/.env @@ -1,2 +0,0 @@ -# No specific domain by default -VITE_API_DOMAIN= diff --git a/404.html b/404.html @@ -8,7 +8,7 @@ <link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"> <title>404 Not Found - Running Tools</title> - <meta name="description" content="A collection of tools for runners and their coaches that calculate splits, predict race times, convert units, and more"> + <meta name="description" content="%VITE_DESCRIPTION%"> </head> <body> diff --git a/README.md b/README.md @@ -45,5 +45,5 @@ npm run test:e2e Build for production ``` -VITE_API_DOMAIN=https://example.com BASE_URL=/running-tools/ npm run build +DOMAIN=example.com BASE_URL=/running-tools/ npm run build ``` diff --git a/index.html b/index.html @@ -8,12 +8,12 @@ <link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"> <title>Running Tools</title> - <meta name="description" content="A collection of tools for runners and their coaches that calculate splits, predict race times, convert units, and more"> + <meta name="description" content="%VITE_DESCRIPTION%"> <meta property="og:title" content="Running Tools"/> - <meta property="og:description" content="A collection of tools for runners and their coaches that calculate splits, predict race times, convert units, and more"/> + <meta property="og:description" content="%VITE_DESCRIPTION%"/> <meta property="og:type" content="website"/> - <meta property="og:url" content="%VITE_API_DOMAIN%%BASE_URL%"/> - <meta property="og:image" content="%VITE_API_DOMAIN%%BASE_URL%img/icons/open-graph-1280x640.png"/> + <meta property="og:url" content="%VITE_DOMAIN%%BASE_URL%"/> + <meta property="og:image" content="%VITE_DOMAIN%%BASE_URL%img/icons/open-graph-1280x640.png"/> <!-- Microsoft tags --> <meta name="msapplication-square70x70logo" content="%BASE_URL%img/icons/mstile-icon-128x128.png"> diff --git a/vite.config.js b/vite.config.js @@ -4,6 +4,8 @@ import { defineConfig } from 'vite'; import { VitePWA } from 'vite-plugin-pwa'; import vue from '@vitejs/plugin-vue'; +import { description } from './package.json'; + // https://vitejs.dev/config/ export default defineConfig({ build: { @@ -19,12 +21,12 @@ export default defineConfig({ VitePWA({ injectRegister: 'inline', manifest: { - name: 'Running Tools', - short_name: 'Running Tools', - description: 'A collection of tools for runners and their coaches that calculate splits, predict race times, convert units, and more', - theme_color: '#ff8000', - background_color: '#ff8000', - icons: [ + name: 'Running Tools', + short_name: 'Running Tools', + description: description, + theme_color: '#ff8000', + background_color: '#ff8000', + icons: [ { "src": "./img/icons/android-chrome-192x192.png", "sizes": "192x192", @@ -56,7 +58,11 @@ export default defineConfig({ '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, - base: process.env.BASE_URL ? process.env.BASE_URL : '/', + base: process.env.BASE_URL || '/', + define: { + 'import.meta.env.VITE_DESCRIPTION': `"${description}"`, + 'import.meta.env.VITE_DOMAIN': process.env.DOMAIN ? `"https://${process.env.DOMAIN}"` : '""', + }, test: { environment: 'jsdom', include: ['tests/unit/**/*.{test,spec}.?(c|m)[jt]s?(x)'],