search console SEO ableitungen

This commit is contained in:
2026-03-23 19:01:52 -05:00
parent d47108d27c
commit e6b19e7a1c
150 changed files with 26257 additions and 25909 deletions

View File

@@ -1,62 +1,62 @@
'use client';
import { useEffect, useState } from 'react';
/**
* Hook to fetch and manage CSRF token for client-side requests
*/
export function useCsrf() {
const [csrfToken, setCsrfToken] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchCsrfToken() {
try {
const response = await fetch('/api/csrf');
const data = await response.json();
setCsrfToken(data.csrfToken);
} catch (error) {
console.error('Failed to fetch CSRF token:', error);
} finally {
setLoading(false);
}
}
fetchCsrfToken();
}, []);
/**
* Helper function to add CSRF token to fetch headers
*/
const getHeaders = (additionalHeaders: HeadersInit = {}) => {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(additionalHeaders as Record<string, string>),
};
if (csrfToken) {
headers['x-csrf-token'] = csrfToken;
}
return headers;
};
/**
* Wrapper for fetch with automatic CSRF token injection
*/
const fetchWithCsrf = async (url: string, options: RequestInit = {}) => {
const headers = getHeaders(options.headers as HeadersInit);
return fetch(url, {
...options,
headers,
});
};
return {
csrfToken,
loading,
getHeaders,
fetchWithCsrf,
};
}
'use client';
import { useEffect, useState } from 'react';
/**
* Hook to fetch and manage CSRF token for client-side requests
*/
export function useCsrf() {
const [csrfToken, setCsrfToken] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function fetchCsrfToken() {
try {
const response = await fetch('/api/csrf');
const data = await response.json();
setCsrfToken(data.csrfToken);
} catch (error) {
console.error('Failed to fetch CSRF token:', error);
} finally {
setLoading(false);
}
}
fetchCsrfToken();
}, []);
/**
* Helper function to add CSRF token to fetch headers
*/
const getHeaders = (additionalHeaders: HeadersInit = {}) => {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(additionalHeaders as Record<string, string>),
};
if (csrfToken) {
headers['x-csrf-token'] = csrfToken;
}
return headers;
};
/**
* Wrapper for fetch with automatic CSRF token injection
*/
const fetchWithCsrf = async (url: string, options: RequestInit = {}) => {
const headers = getHeaders(options.headers as HeadersInit);
return fetch(url, {
...options,
headers,
});
};
return {
csrfToken,
loading,
getHeaders,
fetchWithCsrf,
};
}

View File

@@ -1,61 +1,61 @@
'use client';
import { useState, useEffect } from 'react';
import en from '@/i18n/en.json';
import de from '@/i18n/de.json';
type Locale = 'en' | 'de';
const translations = {
en,
de,
};
export function useTranslation() {
const [locale, setLocale] = useState<Locale>('en');
useEffect(() => {
// Check localStorage for saved locale
const savedLocale = localStorage.getItem('locale') as Locale;
if (savedLocale && (savedLocale === 'en' || savedLocale === 'de')) {
setLocale(savedLocale);
}
}, []);
const changeLocale = (newLocale: Locale) => {
setLocale(newLocale);
localStorage.setItem('locale', newLocale);
};
const t = (key: string, options?: { returnObjects?: boolean }) => {
const keys = key.split('.');
let value: any = translations[locale];
for (const k of keys) {
if (value && typeof value === 'object' && k in value) {
value = value[k];
} else {
// Fallback to English if key not found
value = translations.en;
for (const k of keys) {
if (value && typeof value === 'object' && k in value) {
value = value[k];
} else {
return key; // Return key if not found
}
}
break;
}
}
return value;
};
return {
t,
locale,
language: locale,
setLocale: changeLocale,
setLanguage: changeLocale,
};
'use client';
import { useState, useEffect } from 'react';
import en from '@/i18n/en.json';
import de from '@/i18n/de.json';
type Locale = 'en' | 'de';
const translations = {
en,
de,
};
export function useTranslation() {
const [locale, setLocale] = useState<Locale>('en');
useEffect(() => {
// Check localStorage for saved locale
const savedLocale = localStorage.getItem('locale') as Locale;
if (savedLocale && (savedLocale === 'en' || savedLocale === 'de')) {
setLocale(savedLocale);
}
}, []);
const changeLocale = (newLocale: Locale) => {
setLocale(newLocale);
localStorage.setItem('locale', newLocale);
};
const t = (key: string, options?: { returnObjects?: boolean }) => {
const keys = key.split('.');
let value: any = translations[locale];
for (const k of keys) {
if (value && typeof value === 'object' && k in value) {
value = value[k];
} else {
// Fallback to English if key not found
value = translations.en;
for (const k of keys) {
if (value && typeof value === 'object' && k in value) {
value = value[k];
} else {
return key; // Return key if not found
}
}
break;
}
}
return value;
};
return {
t,
locale,
language: locale,
setLocale: changeLocale,
setLanguage: changeLocale,
};
}