Allow deleting and recreating the homepage

This commit is contained in:
2026-11-28 02:06:27 +08:00
parent 268a278ec1
commit a0df3e60de
11 changed files with 31 additions and 27 deletions
+4 -4
View File
@@ -64,11 +64,11 @@ final class Database
}
}
$pdo->prepare('INSERT OR IGNORE INTO site_settings (id, payload) VALUES (1, ?)')->execute([self::json(['name' => '我的网站'])]);
$pdo->prepare("INSERT OR IGNORE INTO pages
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
VALUES ('home', '首页', '我的网站', '欢迎访问我的网站。', '我的网站', '', '', '', '', '[]', '[]')")
->execute();
if ($version === 0) {
$pdo->prepare("INSERT OR IGNORE INTO pages
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
VALUES ('home', '首页', '我的网站', '欢迎访问我的网站。', '我的网站', '', '', '', '', '[]', '[]')")
->execute();
$articles = $pdo->prepare("INSERT OR IGNORE INTO pages
(slug, name, title, description, heading, accent, lead, image, alt, actions, quicklinks)
VALUES ('articles', '文章与动态', '文章与动态', '浏览站点发布的文章。', '文章与动态', '', '', '', '', '[]', '[]')");
+1 -1
View File
@@ -8,7 +8,7 @@ use RuntimeException;
final class PageDraft
{
public const RESERVED = ['.', '.laysite', 'admin', 'assets', 'home', 'account', 'mcp', 'palette'];
public const RESERVED = ['.', '.laysite', 'admin', 'assets', 'account', 'mcp', 'palette'];
public static function slug(mixed $value, array $reserved = self::RESERVED, bool $includeSpecial = false): string
{
-3
View File
@@ -174,9 +174,6 @@ final class Repository
public function deletePage(string $slug, int $version): bool
{
if ($slug === 'home') {
throw new RuntimeException('首页是站点入口,不能删除。');
}
return Database::write(function (PDO $pdo) use ($slug, $version): bool {
$page = $this->one('SELECT pages.layout_id, d.kind AS layout_kind FROM pages
LEFT JOIN design_presets d ON pages.layout_id = d.id WHERE pages.slug = ?', [$slug]);
+3 -3
View File
@@ -157,8 +157,8 @@ final class SiteBackup
}
}
}
if (count($tables['site_settings']) !== 1 || !in_array('home', array_column($tables['pages'], 'slug'), true)) {
throw new RuntimeException('备份缺少站点身份或首页。');
if (count($tables['site_settings']) !== 1) {
throw new RuntimeException('备份缺少站点身份。');
}
$designs = [];
foreach ($tables['design_presets'] as &$row) {
@@ -198,7 +198,7 @@ final class SiteBackup
$publishedSystemPages[$row['slug']] = $row['page_type'];
}
} elseif ($layout === null) {
PageDraft::slug($row['slug'] ?? null, array_diff(PageDraft::RESERVED, ['home']));
PageDraft::slug($row['slug'] ?? null);
} else {
$kind = is_int($layout) ? ($designs[$layout] ?? null) : null;
if (!in_array($kind, ['header', 'footer'], true) || ($row['slug'] ?? null) !== LayoutPage::slug($kind, $layout)) {