47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
export type SiteEnvironment = 'DEV' | 'STAGING' | null;
|
|
|
|
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',
|
|
'/trackers': 'Trackers',
|
|
'/trackers/books': 'Books',
|
|
'/blog': 'Blog',
|
|
'/lists': 'Lists',
|
|
'/login': 'Sign in',
|
|
'/register': 'Register',
|
|
'/account': 'Account',
|
|
'/projects/game-tracker/pokemon': 'Catchemall',
|
|
'/projects/game-tracker/pokemon/locations': 'Pokémon locations',
|
|
'/projects/animaldex': 'Animaldex',
|
|
'/projects/animaldex/register': 'Log a sighting',
|
|
'/projects/animaldex/admin': 'Animaldex admin',
|
|
'/projects/derby': 'Derby Lens',
|
|
'/projects/cs-prices': 'CS Prices',
|
|
'/projects/energy': 'Energy',
|
|
'/projects/game-tracker': 'Game Tracker',
|
|
'/projects/language-learner': 'Language Learner',
|
|
'/projects/money-tracker': 'Money Tracker',
|
|
'/projects/spotify-beatmap-finder': 'osu! map finder',
|
|
'/projects/progress': 'Progress',
|
|
'/projects/world-opinions': 'World Opinions'
|
|
};
|
|
const cleaned = path.replace(/\/$/, '') || '/';
|
|
const title =
|
|
titles[cleaned] ?? cleaned.split('/').filter(Boolean).at(-1)?.replace(/-/g, ' ') ?? 'Home';
|
|
return formatTitle(title, environment);
|
|
}
|