Files
Goldebek/src/lib/site.ts
T
Per Hoener 0d45331f5c
Deploy / validate-dispatch (push) Successful in 43s
Deploy / scheduled-rebuild-dev (push) Skipped
Deploy / scheduled-rebuild-master (push) Skipped
Deploy / rollback-dev (push) Skipped
Deploy / rollback-master (push) Skipped
Deploy / changes (push) Successful in 13s
Deploy / secret-scan (push) Successful in 9s
Deploy / app-quality (push) Successful in 11m21s
Deploy / security-deps (push) Successful in 14s
Deploy / context (push) Failing after 1s
Deploy / app-image (push) Skipped
Deploy / deploy-dev (push) Skipped
Deploy / deploy-master (push) Skipped
Initial commit
2026-09-18 23:37:19 +02:00

40 lines
1.4 KiB
TypeScript

const DEFAULT_APP_URL = "https://example.com";
function readEnvironment(name: string, fallback: string): string {
return process.env[name]?.trim() || fallback;
}
function normalizeSiteUrl(value: string | undefined): string {
const trimmed = value?.trim();
if (!trimmed) return DEFAULT_APP_URL;
try {
const normalized = new URL(trimmed);
if (!["http:", "https:"].includes(normalized.protocol)) return DEFAULT_APP_URL;
normalized.pathname = normalized.pathname.replace(/\/+$/, "");
return normalized.toString().replace(/\/$/, "");
} catch {
return DEFAULT_APP_URL;
}
}
export const SITE_NAME = readEnvironment("APP_NAME", "Example Website");
export const SITE_URL = normalizeSiteUrl(process.env.APP_URL);
export const COMPANY_NAME = readEnvironment("COMPANY_NAME", "Example Company");
export const CONTACT_EMAIL = readEnvironment("CONTACT_EMAIL", "info@example.com");
export const CONTACT_PHONE = readEnvironment("CONTACT_PHONE", "+49 000 000000");
export const CONTACT_ADDRESS = readEnvironment(
"CONTACT_ADDRESS",
"Example Street 1, 12345 Example City",
);
export function toAbsoluteUrl(pathname: string): string {
if (/^https?:\/\//i.test(pathname)) return pathname;
const normalized = pathname.startsWith("/") ? pathname : `/${pathname}`;
return `${SITE_URL}${normalized}`;
}
export function toPhoneUrl(phone: string): string {
return `tel:${phone.replace(/[^+\d]/g, "")}`;
}