Integrate Prisma for content; enhance SEO, i18n, and deployment workflows
Co-authored-by: dennis <dennis@konkol.net>
This commit is contained in:
30
lib/seo.ts
Normal file
30
lib/seo.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { locales, type AppLocale } from "@/i18n/locales";
|
||||
|
||||
export function getBaseUrl(): string {
|
||||
const raw =
|
||||
process.env.NEXT_PUBLIC_BASE_URL ||
|
||||
process.env.NEXTAUTH_URL || // fallback if ever added
|
||||
"http://localhost:3000";
|
||||
return raw.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
export function toAbsoluteUrl(path: string): string {
|
||||
const base = getBaseUrl();
|
||||
const normalized = path.startsWith("/") ? path : `/${path}`;
|
||||
return `${base}${normalized}`;
|
||||
}
|
||||
|
||||
export function getLanguageAlternates(opts: {
|
||||
/** Path without locale prefix, e.g. "/projects" or "/projects/my-slug" or "" */
|
||||
pathWithoutLocale: string;
|
||||
}): Record<AppLocale, string> {
|
||||
const path = opts.pathWithoutLocale === "" ? "" : `/${opts.pathWithoutLocale}`.replace(/\/{2,}/g, "/");
|
||||
const normalizedPath = path === "/" ? "" : path;
|
||||
|
||||
return locales.reduce((acc, l) => {
|
||||
const url = toAbsoluteUrl(`/${l}${normalizedPath}`);
|
||||
acc[l] = url;
|
||||
return acc;
|
||||
}, {} as Record<AppLocale, string>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user