Add maintenance and 404 pages, template suites, and MCP skill
This commit is contained in:
+14
-10
@@ -30,28 +30,28 @@ final class Repository
|
||||
|
||||
public function pages(bool $publishedOnly = false): array
|
||||
{
|
||||
$where = $publishedOnly ? " WHERE pages.status = 'published' AND pages.layout_id IS NULL" : '';
|
||||
$where = $publishedOnly ? " WHERE pages.status = 'published' AND pages.layout_id IS NULL AND pages.page_type = 'page'" : '';
|
||||
|
||||
return $this->pdo->query('SELECT pages.slug, pages.name, pages.title, pages.updated_at, pages.status, pages.version, d.kind AS layout_kind
|
||||
return $this->pdo->query('SELECT pages.slug, pages.name, pages.title, pages.updated_at, pages.status, pages.version, pages.page_type, d.kind AS layout_kind
|
||||
FROM pages LEFT JOIN design_presets d ON pages.layout_id = d.id' . $where . ' ORDER BY pages.rowid')->fetchAll();
|
||||
}
|
||||
|
||||
public function createPage(string $slug, string $name, array $template = []): void
|
||||
public function createPage(string $slug, string $name, array $template = [], string $type = 'page'): void
|
||||
{
|
||||
Database::write(static fn (PDO $pdo) => self::insertPage($pdo, $slug, $name, $template));
|
||||
Database::write(static fn (PDO $pdo) => self::insertPage($pdo, $slug, $name, $template, type: $type));
|
||||
}
|
||||
|
||||
public static function insertPage(PDO $pdo, string $slug, string $name, array $template = [], ?int $layoutId = null): void
|
||||
public static function insertPage(PDO $pdo, string $slug, string $name, array $template = [], ?int $layoutId = null, string $type = 'page'): void
|
||||
{
|
||||
$query = $pdo->prepare("INSERT OR IGNORE INTO pages (slug, name, title, description, heading, accent,
|
||||
lead, image, alt, actions, quicklinks, theme, visibility, header_id, footer_id, palette_id, layout_id, status, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
lead, image, alt, actions, quicklinks, theme, visibility, header_id, footer_id, palette_id, layout_id, page_type, status, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
$query->execute([
|
||||
$slug, $name, $template['title'] ?? $name, $template['description'] ?? '', $template['heading'] ?? $name,
|
||||
$template['accent'] ?? '', $template['lead'] ?? '', $template['image'] ?? '', $template['alt'] ?? '',
|
||||
Database::json($template['actions'] ?? []), Database::json($template['quicklinks'] ?? []),
|
||||
$template['theme'] ?? '', Database::json($template['visibility'] ?? []), $template['header_id'] ?? null,
|
||||
$template['footer_id'] ?? null, $template['palette_id'] ?? null, $layoutId, $layoutId === null ? 'draft' : 'published', self::now(),
|
||||
$template['footer_id'] ?? null, $template['palette_id'] ?? null, $layoutId, $type, $layoutId === null ? 'draft' : 'published', self::now(),
|
||||
]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此页面地址已存在。');
|
||||
@@ -98,7 +98,7 @@ final class Repository
|
||||
$catalog = $feed['mode'] === 'catalog';
|
||||
$grouped = $network || ($feed['mode'] === 'tabs' && count($feed['categories']) > 1);
|
||||
$archivePath = '/articles/feed/' . $page['slug'] . '/' . $section['key'];
|
||||
$section['archivePath'] = empty($page['layout_kind']) && $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['archivePath'] = empty($page['layout_kind']) && ($page['page_type'] ?? 'page') === 'page' && $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['articleFeed'] = [];
|
||||
$section['networkFeed'] = $network;
|
||||
$section['catalogFeed'] = $catalog;
|
||||
@@ -125,7 +125,8 @@ final class Repository
|
||||
{
|
||||
return $this->one("SELECT sections.title, sections.feed FROM sections
|
||||
JOIN pages ON pages.slug = sections.page_slug
|
||||
WHERE pages.slug = ? AND pages.status = 'published' AND pages.layout_id IS NULL AND sections.key = ? AND sections.feed IS NOT NULL", [$page, $key]);
|
||||
WHERE pages.slug = ? AND pages.status = 'published' AND pages.layout_id IS NULL AND pages.page_type = 'page'
|
||||
AND sections.key = ? AND sections.feed IS NOT NULL", [$page, $key]);
|
||||
}
|
||||
|
||||
public function savePage(string $slug, array $data, int $version, array $sections = [], bool $replaceDraftSections = false, ?array $sectionOrder = null): void
|
||||
@@ -140,6 +141,9 @@ final class Repository
|
||||
isset($data['presentation']) ? CanvasStyle::encode($data['presentation']) : null, $slug, $version,
|
||||
]);
|
||||
self::checkVersion($query->rowCount());
|
||||
if ($data['status'] === 'draft' && str_starts_with($slug, 'system--')) {
|
||||
SiteDesign::unsetSystemPage($pdo, $slug);
|
||||
}
|
||||
if ($replaceDraftSections) {
|
||||
$pdo->prepare('DELETE FROM sections WHERE page_slug = ?')->execute([$slug]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user