Dieselbe Liste trägt die öffentliche Seite. Medien bleiben privat, Seiten können mehreren Säulen zugeordnet sein. Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Domain\Catalog\Pillar;
|
|
use App\Domain\Cms\Page;
|
|
use App\Domain\Cms\PageRevision;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class PageController extends Controller
|
|
{
|
|
public function home(): View
|
|
{
|
|
return $this->render(Page::query()->where('path', '/')->firstOrFail(), preview: false);
|
|
}
|
|
|
|
public function show(string $path): View
|
|
{
|
|
return $this->render(Page::query()->where('path', '/'.$path)->firstOrFail(), preview: false);
|
|
}
|
|
|
|
public function preview(PageRevision $revision): View
|
|
{
|
|
$page = $revision->page;
|
|
Gate::authorize('view', $page);
|
|
|
|
return $this->render($page, preview: true, revision: $revision);
|
|
}
|
|
|
|
public function sitemap(): Response
|
|
{
|
|
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get();
|
|
$themes = Pillar::query()->published()->get();
|
|
|
|
return response()
|
|
->view('public.sitemap', ['pages' => $pages, 'themes' => $themes])
|
|
->header('Content-Type', 'application/xml');
|
|
}
|
|
|
|
private function render(Page $page, bool $preview, ?PageRevision $revision = null): View
|
|
{
|
|
$revision ??= $page->publishedRevision;
|
|
abort_if($revision === null, 404);
|
|
|
|
$heading = collect($revision->blocks)->firstWhere('type', 'heading');
|
|
|
|
return view('public.page', [
|
|
'page' => $page,
|
|
'revision' => $revision,
|
|
'preview' => $preview,
|
|
'documentTitle' => $revision->seo_title ?: ($heading['heading'] ?? config('app.name')),
|
|
'documentDescription' => $revision->seo_description,
|
|
'themes' => $page->path === '/' ? Pillar::query()->published()->get() : collect(),
|
|
]);
|
|
}
|
|
}
|