das marketing frontend wurde auf lokalisierte urls umgestellt.

This commit is contained in:
Codex Agent
2025-11-03 15:50:10 +01:00
parent c0c1d31385
commit 55c606bdd4
47 changed files with 1592 additions and 251 deletions

View File

@@ -3,6 +3,8 @@
namespace App\Http\Controllers;
use App\Models\LegalPage;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Inertia\Inertia;
use Inertia\Response;
@@ -16,21 +18,42 @@ use League\CommonMark\MarkdownConverter;
class LegalPageController extends Controller
{
public function show(?string $slug = null): Response
public function show(Request $request, string $locale, ?string $slug = null): Response
{
$resolvedSlug = $this->resolveSlug($slug);
$page = null;
$page = LegalPage::query()
->where('slug', $resolvedSlug)
->where('is_published', true)
->orderByDesc('version')
->first();
if (! $page) {
abort(404);
try {
$page = LegalPage::query()
->where('slug', $resolvedSlug)
->where('is_published', true)
->orderByDesc('version')
->first();
} catch (QueryException $exception) {
// Table does not exist or query failed; fallback to filesystem documents
$page = null;
}
$locale = $request->route('locale', app()->getLocale());
if (! $page) {
$fallback = $this->loadFallbackDocument($resolvedSlug, $locale);
if (! $fallback) {
abort(404);
}
return Inertia::render('legal/Show', [
'seoTitle' => $fallback['title'].' - '.config('app.name', 'Fotospiel'),
'title' => $fallback['title'],
'content' => $this->convertMarkdownToHtml($fallback['markdown']),
'effectiveFrom' => null,
'effectiveFromLabel' => null,
'versionLabel' => null,
'slug' => $resolvedSlug,
]);
}
$locale = app()->getLocale();
$title = $page->title[$locale]
?? $page->title[$page->locale_fallback]
?? $page->title['de']
@@ -87,4 +110,56 @@ class LegalPageController extends Controller
return trim((string) $converter->convert($markdown));
}
private function loadFallbackDocument(string $slug, string $locale): ?array
{
$candidates = array_unique([
strtolower($locale),
strtolower(config('app.fallback_locale', 'de')),
'de',
'en',
]);
foreach ($candidates as $candidateLocale) {
$path = base_path("docs/legal/{$slug}-{$candidateLocale}.md");
if (! is_file($path)) {
continue;
}
$markdown = (string) file_get_contents($path);
$title = $this->extractTitleFromMarkdown($markdown) ?? Str::title($slug);
return [
'markdown' => $markdown,
'title' => $title,
];
}
return null;
}
private function extractTitleFromMarkdown(string $markdown): ?string
{
foreach (preg_split('/\r?\n/', $markdown) as $line) {
$trimmed = trim($line);
if ($trimmed === '') {
continue;
}
if (str_starts_with($trimmed, '# ')) {
return trim(substr($trimmed, 2));
}
if (str_starts_with($trimmed, '## ')) {
return trim(substr($trimmed, 3));
}
// First non-empty line can act as fallback title
return $trimmed;
}
return null;
}
}