feat: setup globals (Footer), sqlite migration, seed update and access rules

This commit is contained in:
MichalC
2026-08-31 22:37:06 +02:00
parent 5f2eaa0b37
commit 5a9128e2f5
31 changed files with 2281 additions and 362 deletions
+62
View File
@@ -0,0 +1,62 @@
import { i18n } from "../i18n.config";
type LocalizedSlugs = Record<string, string>;
export function clientGetLocalizedSlugs(slugField: any): LocalizedSlugs {
const result: LocalizedSlugs = {};
if (!slugField || typeof slugField !== 'object') {
return result;
}
for (const [locale, value] of Object.entries(slugField)){
if (!i18n.locales.some(l => l.code === locale)) {
continue;
}
if (typeof value !== 'string') {
continue;
}
const slug = value.trim();
if (!slug) {
continue;
}
result[locale] = slug;
}
return result;
}
/**
* Klient-safe wersja funkcji switchLocalePath z ipal-kit, omijająca problem
* importowania modułów Node (np. fs, net) z głównego pliku index.js ipal-kit
* w komponentach "use client".
*/
export function clientSwitchLocalePath(
pathname: string,
targetLocale: string,
slugs?: LocalizedSlugs,
prefix?: LocalizedSlugs,
homeSlug: string = "home"
): string {
// Jeśli mamy zlokalizowane slugi ze strony (przekazane z page.tsx -> Context -> LanguageSwitcher)
if (slugs && slugs[targetLocale]) {
const targetSlug = slugs[targetLocale];
// Jeśli mamy prefix (dla kolekcji, np. /pl/uslugi/...)
if (prefix && prefix[targetLocale]) {
return `/${targetLocale}/${prefix[targetLocale]}/${targetSlug}`;
}
if (targetSlug === homeSlug) {
return `/${targetLocale}`;
}
return `/${targetLocale}/${targetSlug}`;
}
// Fallback (zwykły prefix swap), użyteczny dla stron nienależących do CMS lub
// gdy slugs nie zostały (jeszcze) przekazane do kontekstu
const segments = pathname.split('/').filter(Boolean);
if (segments.length > 0 && i18n.locales.some((l: any) => l.code === segments[0])) {
segments[0] = targetLocale;
} else {
segments.unshift(targetLocale);
}
return `/${segments.join('/')}`;
}