This commit is contained in:
@@ -1,9 +1,40 @@
|
||||
import { dev } from "$app/env";
|
||||
export type SiteEnvironment = 'DEV' | 'STAGING' | null;
|
||||
|
||||
export function getTitle(path: string): string {
|
||||
let builtTitle = "Stan Runge";
|
||||
|
||||
if (dev) builtTitle = "(DEV) " + builtTitle;
|
||||
|
||||
return builtTitle;
|
||||
export function siteEnvironment(isDev: boolean, origin?: string): SiteEnvironment {
|
||||
if (isDev) return 'DEV';
|
||||
try {
|
||||
return new URL(origin ?? '').hostname === 'staging.stanrunge.dev' ? 'STAGING' : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTitle(title: string, environment: SiteEnvironment = null): string {
|
||||
return `${environment ? `(${environment}) ` : ''}${title} | Stan Runge`;
|
||||
}
|
||||
|
||||
export function getTitle(path: string, environment: SiteEnvironment = null): string {
|
||||
const titles: Record<string, string> = {
|
||||
'/': 'Home',
|
||||
'/projects': 'Projects',
|
||||
'/blog': 'Blog',
|
||||
'/lists': 'Lists',
|
||||
'/login': 'Sign in',
|
||||
'/register': 'Register',
|
||||
'/account': 'Account',
|
||||
'/projects/catch-em-all': 'Catchemall',
|
||||
'/projects/animaldex': 'Animaldex',
|
||||
'/projects/animaldex/register': 'Log a sighting',
|
||||
'/projects/animaldex/admin': 'Animaldex admin',
|
||||
'/projects/derby': 'Derby Lens',
|
||||
'/projects/cs-prices': 'CS Prices',
|
||||
'/projects/game-tracker': 'Game Tracker',
|
||||
'/projects/money-tracker': 'Money Tracker',
|
||||
'/projects/spotify-beatmap-finder': 'osu! map finder',
|
||||
'/projects/progress': 'Progress'
|
||||
};
|
||||
const cleaned = path.replace(/\/$/, '') || '/';
|
||||
const title =
|
||||
titles[cleaned] ?? cleaned.split('/').filter(Boolean).at(-1)?.replace(/-/g, ' ') ?? 'Home';
|
||||
return formatTitle(title, environment);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user