forked from laysense/laysense.cn
Add whole-page template collections and Caddy examples
This commit is contained in:
@@ -35,15 +35,25 @@ final class Repository
|
||||
return $this->pdo->query('SELECT slug, name, title, updated_at, status FROM pages' . $where . ' ORDER BY rowid')->fetchAll();
|
||||
}
|
||||
|
||||
public function createPage(string $slug, string $name): void
|
||||
public function createPage(string $slug, string $name, array $template = []): void
|
||||
{
|
||||
$query = $this->pdo->prepare("INSERT OR IGNORE INTO pages (slug, name, title, description, heading, accent,
|
||||
lead, image, alt, actions, quicklinks, status, updated_at)
|
||||
VALUES (?, ?, ?, '', ?, '', '', '', '', '[]', '[]', 'draft', ?)");
|
||||
$query->execute([$slug, $name, $name . ' · 来笙', $name, self::now()]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此页面地址已存在。');
|
||||
}
|
||||
Database::write(function (PDO $pdo) use ($slug, $name, $template): void {
|
||||
$query = $pdo->prepare("INSERT OR IGNORE INTO pages (slug, name, title, description, heading, accent,
|
||||
lead, image, alt, actions, quicklinks, theme, status, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'draft', ?)");
|
||||
$query->execute([
|
||||
$slug, $name, $name . ' · 来笙', $template['description'] ?? '', $template['heading'] ?? $name,
|
||||
$template['accent'] ?? '', $template['lead'] ?? '', $template['image'] ?? '', $template['alt'] ?? '',
|
||||
Database::json($template['actions'] ?? []), Database::json($template['quicklinks'] ?? []),
|
||||
$template['theme'] ?? '', self::now(),
|
||||
]);
|
||||
if ($query->rowCount() !== 1) {
|
||||
throw new RuntimeException('此页面地址已存在。');
|
||||
}
|
||||
foreach ($template['sections'] ?? [] as $section) {
|
||||
self::insertSection($pdo, $slug, $section['key'], $section);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function page(string $slug): ?array
|
||||
|
||||
Reference in New Issue
Block a user