All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 9s
18 lines
620 B
TypeScript
18 lines
620 B
TypeScript
// src/utils/paths.ts
|
|
|
|
// Wir greifen auf die Umgebungsvariable von Astro zu
|
|
const base = import.meta.env.BASE_URL;
|
|
|
|
/**
|
|
* Erstellt einen korrekten Pfad unter Berücksichtigung der Astro 'base' Konfiguration.
|
|
* Verhindert doppelte Slashes und funktioniert in Dev, Test und Prod.
|
|
*/
|
|
export function getPath(path: string): string {
|
|
// Entfernt den Slash am Ende der Base, falls vorhanden
|
|
const normalizedBase = base.replace(/\/$/, '');
|
|
|
|
// Stellt sicher, dass der Pfad mit einem Slash beginnt
|
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
|
|
return `${normalizedBase}${normalizedPath}`;
|
|
} |