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
+25 -4
View File
@@ -12,7 +12,7 @@ use Throwable;
final class SiteBackup
{
private const FORMAT = 'laysite-site';
private const VERSION = 3;
private const VERSION = 4;
private const TABLES = [
'site_settings', 'design_presets', 'pages', 'sections', 'article_categories', 'articles',
'article_category_links', 'article_redirects', 'article_deletions', 'media',
@@ -140,7 +140,7 @@ final class SiteBackup
private static function prepare(mixed $manifest): array
{
if (!is_array($manifest) || ($manifest['format'] ?? '') !== self::FORMAT
|| !in_array($manifest['version'] ?? null, [1, 2, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|| !in_array($manifest['version'] ?? null, [1, 2, 3, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
throw new RuntimeException('备份格式不受支持,请使用相同或更新版本的 LaySite。');
}
$tables = $manifest['tables'];
@@ -184,10 +184,18 @@ final class SiteBackup
$site['layout_defaults'][$kind] = self::selection($designs, $kind, $layoutDefaults[$kind]);
}
}
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
$publishedSystemPages = [];
foreach ($tables['pages'] as &$row) {
$layout = $row['layout_id'] ?? null;
if ($layout === null) {
$row['page_type'] ??= 'page';
if ($row['page_type'] !== 'page') {
if ($layout !== null || !is_string($row['page_type']) || !SystemPage::slugMatches($row['page_type'], $row['slug'] ?? null)) {
throw new RuntimeException('备份包含无效的系统页面。');
}
if (($row['status'] ?? null) === 'published') {
$publishedSystemPages[$row['slug']] = $row['page_type'];
}
} elseif ($layout === null) {
PageDraft::slug($row['slug'] ?? null, array_diff(PageDraft::RESERVED, ['home']));
} else {
$kind = is_int($layout) ? ($designs[$layout] ?? null) : null;
@@ -210,6 +218,19 @@ final class SiteBackup
}
}
unset($row);
$systemPages = $settings['system_pages'] ?? [];
$maintenance = $settings['maintenance_enabled'] ?? false;
if (!is_array($systemPages) || !is_bool($maintenance) || ($maintenance && !isset($systemPages['maintenance']))) {
throw new RuntimeException('备份包含无效的系统页面设置。');
}
foreach ($systemPages as $type => $slug) {
if (!is_string($slug) || ($publishedSystemPages[$slug] ?? null) !== $type) {
throw new RuntimeException('备份引用了缺失或未发布的系统页面。');
}
}
$site['system_pages'] = $systemPages;
$site['maintenance_enabled'] = $maintenance;
$tables['site_settings'] = [['id' => 1, 'payload' => Database::json($site)]];
foreach ($tables['sections'] as &$row) {
PageDraft::slug($row['key'] ?? null, ['home', 'contact', 'main-content', 'primary-navigation', 'preview']);
if (!in_array($row['style'] ?? '', ['plain', 'tinted', 'hero-links', 'layout'], true)) {