Add maintenance and 404 pages, template suites, and MCP skill

This commit is contained in:
2026-11-25 15:36:01 +08:00
parent 277610913a
commit 884ce10789
47 changed files with 470 additions and 52 deletions
+19 -2
View File
@@ -9,6 +9,7 @@ use App\Content\DesignFieldError;
use App\Content\DesignLibrary;
use App\Content\Repository;
use App\Content\SiteDesign;
use App\Content\SystemPage;
use App\Http\Request;
use RuntimeException;
use support\Response;
@@ -76,10 +77,13 @@ final class DesignController extends AdminController
if ($failure = $this->guard($request)) {
return $failure;
}
$site = (new Repository())->site();
$repo = new Repository();
$site = $repo->site();
$error = '';
$name = $site['name'];
$cdn = $site['cdn']['origin'] ?? '';
$systemPages = $site['system_pages'] ?? [];
$maintenance = $site['maintenance_enabled'] ?? false;
$version = (int) ($site['revisions']['general'] ?? 0);
if ($request->method() === 'POST') {
try {
@@ -88,7 +92,12 @@ final class DesignController extends AdminController
if ($name === '' || mb_strlen($name) > 100) {
throw new RuntimeException('站点名称必须为 1 至 100 个字符。');
}
SiteDesign::saveGeneral($name, $cdn, $this->version($request));
$systemPages = array_filter([
'maintenance' => $this->input($request, 'maintenance_page'),
'not-found' => $this->input($request, 'not_found_page'),
], static fn (string $slug): bool => $slug !== '');
$maintenance = $request->post('maintenance_enabled') === '1';
SiteDesign::saveGeneral($name, $cdn, $this->version($request), $systemPages, $maintenance);
return $this->success($request, '/admin/settings?saved=1');
} catch (RuntimeException $ex) {
@@ -96,8 +105,16 @@ final class DesignController extends AdminController
}
}
$systemChoices = [];
foreach ($repo->pages() as $page) {
$type = $page['page_type'];
if (isset(SystemPage::TYPES[$type]) && $page['status'] === 'published') {
$systemChoices[$type][$page['slug']] = $page['name'];
}
}
return $this->render($request, 'studio-settings', [
'title' => '站点设置', 'name' => $name, 'cdn' => $cdn, 'version' => $version, 'error' => $error,
'systemPages' => $systemPages, 'systemChoices' => $systemChoices, 'maintenance' => $maintenance,
'saved' => $request->get('saved') === '1',
], $error === '' ? 200 : 422);
}