forked from laysense/laysite
Prepare LaySite 1.5.1 page routing and template updates
This commit is contained in:
@@ -12,7 +12,7 @@ use Throwable;
|
||||
final class Database
|
||||
{
|
||||
public const MIGRATION_REQUIRED = '数据库尚未完成升级。请在站点目录运行 php bin/install.php。';
|
||||
private const SCHEMA_VERSION = 8;
|
||||
private const SCHEMA_VERSION = 9;
|
||||
// Avoid reusing a deleted ID that may still be open in an editing form.
|
||||
public const NEXT_ARTICLE_ID = 'MAX(COALESCE((SELECT MAX(id) FROM articles), 0),
|
||||
COALESCE((SELECT MAX(article_id) FROM article_deletions), 0)) + 1';
|
||||
@@ -54,7 +54,8 @@ final class Database
|
||||
if ($version > self::SCHEMA_VERSION) {
|
||||
throw new RuntimeException('当前 SQLite 数据库需要更新版本的 LaySite。');
|
||||
}
|
||||
$pdo->exec(file_get_contents($root . '/resources/schema.sql'));
|
||||
$schema = file_get_contents($root . '/resources/schema.sql');
|
||||
$pdo->exec($schema);
|
||||
if ($version < 3) {
|
||||
foreach (['pages', 'sections'] as $table) {
|
||||
$columns = $pdo->query('PRAGMA table_info(' . $table . ')')->fetchAll();
|
||||
@@ -101,12 +102,32 @@ final class Database
|
||||
if ($version < 5) {
|
||||
LayoutPage::migrate($pdo);
|
||||
}
|
||||
if ($version < 9) {
|
||||
self::migratePageRoutes($pdo, $schema);
|
||||
DesignLibrary::ensureDefaultPalette($pdo);
|
||||
}
|
||||
if ($version < self::SCHEMA_VERSION) {
|
||||
$pdo->exec('PRAGMA user_version = ' . self::SCHEMA_VERSION);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static function migratePageRoutes(PDO $pdo, string $schema): void
|
||||
{
|
||||
// Renaming the parent also retargets the old child table's foreign key.
|
||||
$pdo->exec('ALTER TABLE pages RENAME TO pages_before_routes');
|
||||
$pdo->exec('ALTER TABLE sections RENAME TO sections_before_routes');
|
||||
$pdo->exec($schema);
|
||||
foreach (['pages', 'sections'] as $table) {
|
||||
$columns = implode(', ', array_column($pdo->query("PRAGMA table_info($table)")->fetchAll(), 'name'));
|
||||
$pdo->exec("INSERT INTO $table (rowid, $columns) SELECT rowid, $columns FROM {$table}_before_routes");
|
||||
}
|
||||
$pdo->exec('DROP TABLE sections_before_routes');
|
||||
$pdo->exec('DROP TABLE pages_before_routes');
|
||||
$pdo->exec('CREATE UNIQUE INDEX pages_layout_id ON pages(layout_id)');
|
||||
$pdo->exec("UPDATE pages SET page_type = 'home' WHERE slug = 'home' AND page_type = 'page' AND layout_id IS NULL");
|
||||
}
|
||||
|
||||
public static function write(callable $operation): mixed
|
||||
{
|
||||
$pdo = self::connect();
|
||||
|
||||
@@ -39,9 +39,27 @@ final class DesignLibrary
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
||||
public static function ensureDefaultPalette(PDO $pdo): void
|
||||
{
|
||||
$site = json_decode((string) $pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
if (isset($site['palette_id'])) {
|
||||
return;
|
||||
}
|
||||
$pdo->prepare("INSERT INTO design_presets (kind, name, preset, payload) VALUES ('palette', ?, 'custom', ?)")
|
||||
->execute(['默认配色', Database::json(self::defaults('palette'))]);
|
||||
$site['palette_id'] = (int) $pdo->lastInsertId();
|
||||
$pdo->prepare('UPDATE site_settings SET payload = ? WHERE id = 1')->execute([Database::json($site)]);
|
||||
}
|
||||
|
||||
public static function layouts(): array
|
||||
{
|
||||
return Database::connect()->query("SELECT d.id, d.kind, d.name, pages.slug FROM design_presets d
|
||||
JOIN pages ON pages.layout_id = d.id WHERE d.kind IN ('header', 'footer') ORDER BY d.kind, d.id")->fetchAll();
|
||||
}
|
||||
|
||||
public static function palettes(): array
|
||||
{
|
||||
$rows = Database::connect()->query("SELECT id, name, preset, payload FROM design_presets
|
||||
$rows = Database::connect()->query("SELECT id, name, preset, payload, version FROM design_presets
|
||||
WHERE kind = 'palette' ORDER BY id")->fetchAll();
|
||||
foreach ($rows as &$row) {
|
||||
$row['colors'] = self::normalize('palette', $row['preset'], json_decode($row['payload'], true, flags: JSON_THROW_ON_ERROR));
|
||||
|
||||
@@ -9,25 +9,14 @@ use RuntimeException;
|
||||
|
||||
final class LayoutPage
|
||||
{
|
||||
public const TYPES = ['page' => '普通页面', 'header' => '页头', 'footer' => '页脚'];
|
||||
public const TYPES = ['page' => '普通页面', 'home' => '首页', 'header' => '页头', 'footer' => '页脚'];
|
||||
|
||||
public static function slug(string $kind, int $id): string
|
||||
{
|
||||
return "layout--$kind-$id";
|
||||
}
|
||||
|
||||
public static function create(string $kind, string $name): string
|
||||
{
|
||||
return Database::write(static function (PDO $pdo) use ($kind, $name): string {
|
||||
$id = self::insertPreset($pdo, $kind, $name);
|
||||
$slug = self::slug($kind, $id);
|
||||
Repository::insertPage($pdo, $slug, $name, ['visibility' => ['hero' => false]], $id);
|
||||
|
||||
return $slug;
|
||||
});
|
||||
}
|
||||
|
||||
private static function insertPreset(PDO $pdo, string $kind, string $name): int
|
||||
public static function insertPreset(PDO $pdo, string $kind, string $name): int
|
||||
{
|
||||
$pdo->prepare('INSERT INTO design_presets (kind, name, preset, payload) VALUES (?, ?, ?, ?)')
|
||||
->execute([$kind, $name, array_key_first(DesignLibrary::PRESETS[$kind]), Database::json(DesignLibrary::defaults($kind))]);
|
||||
|
||||
+43
-11
@@ -30,15 +30,26 @@ final class Repository
|
||||
|
||||
public function pages(bool $publishedOnly = false): array
|
||||
{
|
||||
$where = $publishedOnly ? " WHERE pages.status = 'published' AND pages.layout_id IS NULL AND pages.page_type = 'page'" : '';
|
||||
$where = $publishedOnly ? " WHERE pages.status = 'published' AND pages.layout_id IS NULL AND pages.page_type IN ('page', 'home')" : '';
|
||||
|
||||
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
|
||||
return $this->pdo->query('SELECT pages.slug, pages.name, pages.title, pages.updated_at, pages.status, pages.version, pages.page_type, pages.layout_id, 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 homepage(): ?array
|
||||
{
|
||||
$result = $this->one("SELECT slug FROM pages WHERE page_type = 'home'
|
||||
AND layout_id IS NULL AND status = 'published' ORDER BY RANDOM() LIMIT 1", []);
|
||||
|
||||
return $result ? $this->page($result['slug']) : null;
|
||||
}
|
||||
|
||||
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, type: $type));
|
||||
Database::write(static function (PDO $pdo) use ($slug, $name, $template, $type): void {
|
||||
$layout = in_array($type, ['header', 'footer'], true) ? LayoutPage::insertPreset($pdo, $type, $name) : null;
|
||||
self::insertPage($pdo, $slug, $name, $template, $layout, $layout === null ? $type : 'page');
|
||||
});
|
||||
}
|
||||
|
||||
public static function insertPage(PDO $pdo, string $slug, string $name, array $template = [], ?int $layoutId = null, string $type = 'page'): void
|
||||
@@ -98,7 +109,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'] = $feed['categories'] && empty($page['layout_kind']) && ($page['page_type'] ?? 'page') === 'page' && $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['archivePath'] = $feed['categories'] && empty($page['layout_kind']) && in_array($page['page_type'] ?? 'page', ['page', 'home'], true) && $page['status'] === 'published' ? $archivePath : null;
|
||||
$section['articleFeed'] = [];
|
||||
$section['networkFeed'] = $network;
|
||||
$section['catalogFeed'] = $catalog;
|
||||
@@ -125,29 +136,50 @@ 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 pages.page_type = 'page'
|
||||
WHERE pages.slug = ? AND pages.status = 'published' AND pages.layout_id IS NULL AND pages.page_type IN ('page', 'home')
|
||||
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): array
|
||||
{
|
||||
return Database::write(function (PDO $pdo) use ($slug, $data, $version, $sections, $replaceDraftSections, $sectionOrder): array {
|
||||
$existing = $this->one('SELECT pages.version, pages.page_type, 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]);
|
||||
self::checkVersion($existing !== null && $existing['version'] === $version ? 1 : 0);
|
||||
$target = $data['slug'] ?? $slug;
|
||||
if ($target !== $slug && $this->one('SELECT 1 FROM pages WHERE slug = ?', [$target])) {
|
||||
throw new RuntimeException('此页面地址已存在。');
|
||||
}
|
||||
$previousType = $existing['layout_kind'] ?? $existing['page_type'];
|
||||
$type = $data['type'] ?? $previousType;
|
||||
$layout = $existing['layout_id'];
|
||||
if ($type !== $previousType) {
|
||||
$layout = in_array($type, ['header', 'footer'], true) ? LayoutPage::insertPreset($pdo, $type, $data['name']) : null;
|
||||
}
|
||||
$head = $data['head_html'] ?? null;
|
||||
$query = $pdo->prepare('UPDATE pages SET name = ?, title = ?, description = ?, heading = ?, accent = ?, lead = ?,
|
||||
$query = $pdo->prepare('UPDATE pages SET slug = ?, page_type = ?, layout_id = ?, name = ?, title = ?, description = ?, heading = ?, accent = ?, lead = ?,
|
||||
image = ?, alt = ?, image_scale = ?, alignments = ?, actions = ?, quicklinks = ?, visibility = ?, header_id = ?, footer_id = ?, palette_id = ?, status = ?, updated_at = ?,
|
||||
presentation = COALESCE(?, presentation), ' . ($head === null ? '' : 'head_html = ?, ')
|
||||
. 'version = version + 1 WHERE slug = ? AND version = ?');
|
||||
$query->execute([
|
||||
$data['name'], $data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
|
||||
$target, $layout === null ? $type : 'page', $layout, $data['name'], $data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
|
||||
$data['image'], $data['alt'], $data['image_scale'], Database::json($data['alignments']), Database::json($data['actions']), Database::json($data['quicklinks']),
|
||||
Database::json($data['visibility']), $data['header_id'], $data['footer_id'], $data['palette_id'], $data['status'], self::now(),
|
||||
isset($data['presentation']) ? CanvasStyle::encode($data['presentation']) : null,
|
||||
...($head === null ? [] : [$head]), $slug, $version,
|
||||
]);
|
||||
self::checkVersion($query->rowCount());
|
||||
if ($data['status'] === 'draft' && str_starts_with($slug, 'system--')) {
|
||||
SiteDesign::unsetSystemPage($pdo, $slug);
|
||||
if (isset(SystemPage::TYPES[$previousType])) {
|
||||
if ($data['status'] === 'draft' || $previousType !== $type) {
|
||||
SiteDesign::replaceSystemPage($pdo, $slug);
|
||||
} elseif ($target !== $slug) {
|
||||
SiteDesign::replaceSystemPage($pdo, $slug, replacement: $target);
|
||||
}
|
||||
}
|
||||
if ($existing['layout_id'] !== null && $layout !== $existing['layout_id']) {
|
||||
LayoutPage::deletePreset($pdo, $existing['layout_kind'], $existing['layout_id']);
|
||||
}
|
||||
$slug = $target;
|
||||
if ($replaceDraftSections) {
|
||||
$pdo->prepare('DELETE FROM sections WHERE page_slug = ?')->execute([$slug]);
|
||||
}
|
||||
@@ -164,7 +196,7 @@ final class Repository
|
||||
self::writeSectionOrder($pdo, $slug, $sectionOrder);
|
||||
}
|
||||
$page = $this->page($slug);
|
||||
if (isset($data['layoutConfig'])) {
|
||||
if ($type === $previousType && $layout !== null && isset($data['layoutConfig'])) {
|
||||
LayoutPage::saveSettings($pdo, $page, $data['layoutConfig']);
|
||||
}
|
||||
|
||||
@@ -186,7 +218,7 @@ final class Repository
|
||||
if ($page['layout_id'] !== null) {
|
||||
LayoutPage::deletePreset($pdo, $page['layout_kind'], $page['layout_id']);
|
||||
}
|
||||
SiteDesign::unsetSystemPage($pdo, $slug);
|
||||
SiteDesign::replaceSystemPage($pdo, $slug);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
+21
-13
@@ -12,7 +12,7 @@ use Throwable;
|
||||
final class SiteBackup
|
||||
{
|
||||
private const FORMAT = 'laysite-site';
|
||||
private const VERSION = 5;
|
||||
private const VERSION = 6;
|
||||
private const TABLES = [
|
||||
'site_settings', 'design_presets', 'pages', 'sections', 'article_categories', 'articles',
|
||||
'article_category_links', 'article_redirects', 'article_deletions', 'media',
|
||||
@@ -111,6 +111,7 @@ final class SiteBackup
|
||||
}
|
||||
Database::write(function (PDO $pdo) use ($tables, $staged, $directory, &$installed): void {
|
||||
self::replaceTables($pdo, $tables);
|
||||
DesignLibrary::ensureDefaultPalette($pdo);
|
||||
foreach ($staged as $name => $source) {
|
||||
$target = $directory . '/' . $name;
|
||||
if (is_file($target) && !is_link($target) && hash_file('sha256', $target) === hash_file('sha256', $source)) {
|
||||
@@ -140,7 +141,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, 3, 4, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|
||||
|| !in_array($manifest['version'] ?? null, [1, 2, 3, 4, 5, self::VERSION], true) || !is_array($manifest['tables'] ?? null)) {
|
||||
throw new RuntimeException('备份格式不受支持,请使用相同或更新版本的 LaySite。');
|
||||
}
|
||||
$tables = $manifest['tables'];
|
||||
@@ -174,6 +175,9 @@ final class SiteBackup
|
||||
$site = ['name' => $settings['name'], 'cdn' => ['origin' => Assets::cdn($settings['cdn']['origin'] ?? '')], 'revisions' => ['general' => time()]];
|
||||
$site['head_html'] = PageHead::normalize($settings['head_html'] ?? '');
|
||||
$site['favicon'] = SiteIcon::normalize($settings['favicon'] ?? '');
|
||||
if (isset($settings['palette_id'])) {
|
||||
$site['palette_id'] = self::selection($designs, 'palette', $settings['palette_id']);
|
||||
}
|
||||
$layoutDefaults = $settings['layout_defaults'] ?? [];
|
||||
if (!is_array($layoutDefaults)) {
|
||||
throw new RuntimeException('备份的基础页头页脚配置无效。');
|
||||
@@ -190,21 +194,25 @@ final class SiteBackup
|
||||
foreach ($tables['pages'] as &$row) {
|
||||
$layout = $row['layout_id'] ?? 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);
|
||||
} else {
|
||||
PageDraft::slug($row['slug'] ?? null, includeSpecial: true);
|
||||
if ($manifest['version'] < 6 && $layout === null && $row['slug'] === 'home' && $row['page_type'] === 'page') {
|
||||
$row['page_type'] = 'home';
|
||||
}
|
||||
if (!is_string($row['page_type'])) {
|
||||
throw new RuntimeException('备份包含无效的页面类型。');
|
||||
}
|
||||
if ($layout !== null) {
|
||||
$kind = is_int($layout) ? ($designs[$layout] ?? null) : null;
|
||||
if (!in_array($kind, ['header', 'footer'], true) || ($row['slug'] ?? null) !== LayoutPage::slug($kind, $layout)) {
|
||||
if (!in_array($kind, ['header', 'footer'], true) || $row['page_type'] !== 'page') {
|
||||
throw new RuntimeException('备份包含无效的页头或页脚页面。');
|
||||
}
|
||||
$row['status'] = 'published';
|
||||
} elseif (isset(SystemPage::TYPES[$row['page_type']])) {
|
||||
if (($row['status'] ?? null) === 'published') {
|
||||
$publishedSystemPages[$row['slug']] = $row['page_type'];
|
||||
}
|
||||
} elseif (!in_array($row['page_type'], ['page', 'home'], true)) {
|
||||
throw new RuntimeException('备份包含无效的页面类型。');
|
||||
}
|
||||
self::validateAssetUrl($row['image'] ?? '', true);
|
||||
$row['actions'] = Database::json(Buttons::validate(self::decode($row['actions'] ?? '[]')));
|
||||
|
||||
@@ -63,16 +63,20 @@ final class SiteDesign
|
||||
});
|
||||
}
|
||||
|
||||
public static function unsetSystemPage(PDO $pdo, string $slug): void
|
||||
public static function replaceSystemPage(PDO $pdo, string $slug, ?string $replacement = null): void
|
||||
{
|
||||
$site = json_decode((string) $pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
$type = array_search($slug, $site['system_pages'] ?? [], true);
|
||||
if ($type === false) {
|
||||
return;
|
||||
}
|
||||
unset($site['system_pages'][$type]);
|
||||
if ($type === 'maintenance') {
|
||||
$site['maintenance_enabled'] = false;
|
||||
if ($replacement !== null) {
|
||||
$site['system_pages'][$type] = $replacement;
|
||||
} else {
|
||||
unset($site['system_pages'][$type]);
|
||||
if ($type === 'maintenance') {
|
||||
$site['maintenance_enabled'] = false;
|
||||
}
|
||||
}
|
||||
$site['revisions']['general'] = ($site['revisions']['general'] ?? 0) + 1;
|
||||
$pdo->prepare('UPDATE site_settings SET payload = ? WHERE id = 1')->execute([Database::json($site)]);
|
||||
|
||||
@@ -16,7 +16,7 @@ final class SystemPage
|
||||
|
||||
public static function published(Repository $repo, string $type, mixed $slug): ?array
|
||||
{
|
||||
if (!self::slugMatches($type, $slug)) {
|
||||
if (!isset(self::TYPES[$type]) || !is_string($slug) || $slug === '') {
|
||||
return null;
|
||||
}
|
||||
$page = $repo->page($slug);
|
||||
|
||||
@@ -12,6 +12,8 @@ use App\Content\Database;
|
||||
use App\Content\Html;
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\PageHead;
|
||||
use App\Content\PageDraft;
|
||||
use App\Content\SystemPage;
|
||||
use App\Content\Licenses;
|
||||
use App\Content\Media;
|
||||
use App\Content\Passwords;
|
||||
@@ -351,9 +353,6 @@ class AdminController
|
||||
$data[$field] = CanvasStyle::lineBreaks($data[$field]);
|
||||
}
|
||||
$data['name'] = $request->post('name') === null ? $page['name'] : $this->input($request, 'name');
|
||||
if ($layout) {
|
||||
$data['title'] = $data['name'];
|
||||
}
|
||||
$publication = $request->post('status');
|
||||
$data['status'] = $layout || $publication === null ? $page['status'] : $this->input($request, 'status');
|
||||
$scale = $this->input($request, 'image_scale');
|
||||
@@ -365,6 +364,20 @@ class AdminController
|
||||
$page['head_html'] = $head;
|
||||
}
|
||||
try {
|
||||
$previousType = $layoutKind ?? $page['page_type'];
|
||||
$type = $request->post('page_type') === null ? $previousType : $this->input($request, 'page_type');
|
||||
if (!isset((LayoutPage::TYPES + SystemPage::TYPES)[$type])) {
|
||||
throw new RuntimeException('请选择可用的页面类型。');
|
||||
}
|
||||
$target = $request->post('page_slug') === null ? $slug : $this->input($request, 'page_slug');
|
||||
$data['slug'] = $target === $slug ? $slug : PageDraft::slug($target);
|
||||
$data['type'] = $type;
|
||||
$public = in_array($type, ['page', 'home'], true);
|
||||
if (in_array($type, ['header', 'footer'], true)) {
|
||||
$data['status'] = 'published';
|
||||
} elseif ($public && !in_array($previousType, ['page', 'home'], true)) {
|
||||
$data['status'] = 'draft';
|
||||
}
|
||||
if ($head !== null) {
|
||||
if (!$headEditor) {
|
||||
throw new RuntimeException(Database::MIGRATION_REQUIRED);
|
||||
@@ -421,7 +434,7 @@ class AdminController
|
||||
$data['quicklinks'] = $request->post('quicklinks') === null ? $page['quicklinks'] : SiteDesign::parseLinks($this->input($request, 'quicklinks'));
|
||||
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|
||||
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
(!$layout && $page['page_type'] === 'page' && $data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
($public && $data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
(($data['visibility']['hero'] ?? true) && !array_key_exists('heroHtml', $data['presentation']) && $data['heading'] === '') || mb_strlen($data['heading'] . $data['accent']) > 110 ||
|
||||
mb_strlen($data['lead']) > 600 || mb_strlen($data['alt']) > 200 ||
|
||||
($data['image_scale'] !== 0 && ($data['image_scale'] < CanvasStyle::MIN_MEDIA_SCALE || $data['image_scale'] > 100)) ||
|
||||
@@ -438,7 +451,11 @@ class AdminController
|
||||
}
|
||||
}
|
||||
$saved = $repo->savePage($slug, $data, $this->version($request), $sections, sectionOrder: $order === '' ? null : $order);
|
||||
$editor = '/admin/pages/' . $saved['slug'] . '?saved=1';
|
||||
if ($request->expectsJson()) {
|
||||
if ($target !== $slug || $type !== $previousType) {
|
||||
return $this->json(['saved' => true, 'redirect' => $editor]);
|
||||
}
|
||||
return $this->json([
|
||||
'saved' => true, 'version' => $saved['version'], 'name' => $saved['name'], 'status' => $saved['status'],
|
||||
'sections' => array_map(static function (array $section) use ($sections): array {
|
||||
@@ -449,7 +466,7 @@ class AdminController
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $slug . '?saved=1');
|
||||
return $this->success($request, $editor);
|
||||
} catch (RuntimeException $exception) {
|
||||
$error = $this->validationMessage($exception);
|
||||
}
|
||||
@@ -457,11 +474,11 @@ class AdminController
|
||||
|
||||
return $this->render($request, 'admin-page', [
|
||||
'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'canvasSourceEditor' => true, 'error' => $error, 'saved' => $request->get('saved') === '1',
|
||||
'pageTemplateDrawer' => !$layout, 'headEditor' => $headEditor, 'designs' => DesignLibrary::all(), 'layout' => $layout, 'layoutDefault' => $default,
|
||||
'pageTemplateDrawer' => !$layout, 'headEditor' => $headEditor, 'designs' => DesignLibrary::layouts(), 'layout' => $layout, 'layoutDefault' => $default,
|
||||
'layoutBase' => $layout && ($site['layout_defaults'][$layoutKind] ?? null) === $layout['id'],
|
||||
'siteName' => $site['name'], 'layoutHasMember' => $layoutKind === 'header' && LayoutPage::hasMember($page['sections']),
|
||||
'layoutDefaults' => array_intersect_key($site, ['header_id' => true, 'footer_id' => true]),
|
||||
'palettes' => DesignLibrary::palettes(),
|
||||
'palettes' => DesignLibrary::palettes(), 'defaultPaletteId' => $site['palette_id'] ?? null,
|
||||
], $error !== '' ? 422 : 200);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Content\DesignFieldError;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\McpSettings;
|
||||
use App\Content\PageHead;
|
||||
use App\Content\PageTemplates;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\SiteIcon;
|
||||
@@ -27,7 +28,7 @@ final class DesignController extends AdminController
|
||||
}
|
||||
|
||||
return $this->render($request, 'admin-design', [
|
||||
'title' => '站点设计', 'items' => DesignLibrary::palettes(),
|
||||
'title' => '站点设计', 'items' => DesignLibrary::palettes(), 'defaultPaletteId' => (new Repository())->site()['palette_id'] ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ final class DesignController extends AdminController
|
||||
return $this->error($request, '找不到这项设计配置。', 404);
|
||||
}
|
||||
$repo = new Repository();
|
||||
$page = $repo->page('home');
|
||||
$page = $repo->homepage() ?? PageTemplates::find('cobalt-product');
|
||||
$page[$kind . '_id'] = (int) $id;
|
||||
|
||||
return (new SiteController())->renderPage($repo, $page, true);
|
||||
|
||||
@@ -19,7 +19,11 @@ final class SiteController
|
||||
{
|
||||
public function home(Request $request): Response
|
||||
{
|
||||
return $this->page($request, 'home');
|
||||
$repo = new Repository();
|
||||
$page = $repo->homepage();
|
||||
$response = $page ? $this->renderPage($repo, $page, root: true) : $this->missing($request);
|
||||
|
||||
return $response->withHeader('Cache-Control', 'no-store');
|
||||
}
|
||||
|
||||
public function license(Request $request): Response
|
||||
@@ -35,8 +39,8 @@ final class SiteController
|
||||
{
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
if (!$page || $page['layout_kind'] !== null || $page['page_type'] !== 'page'
|
||||
|| $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
|
||||
if (!$page || $page['layout_kind'] !== null || !in_array($page['page_type'], ['page', 'home'], true)
|
||||
|| $page['status'] !== 'published') {
|
||||
return $this->missing($request);
|
||||
}
|
||||
if ($slug === 'articles' && $request->get('page') !== null) {
|
||||
@@ -52,17 +56,17 @@ final class SiteController
|
||||
return $this->renderPage($repo, $page);
|
||||
}
|
||||
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false, bool $canvas = false, int $status = 200): Response
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false, bool $canvas = false, int $status = 200, bool $root = false): Response
|
||||
{
|
||||
$slug = $page['slug'];
|
||||
$isHome = $slug === 'home';
|
||||
$showHero = $page['visibility']['hero'] ?? true;
|
||||
$page = $repo->withSectionFeeds($page);
|
||||
|
||||
return View::render('page', [
|
||||
'site' => $repo->site(),
|
||||
'page' => $page,
|
||||
'path' => ($page['page_type'] ?? 'page') !== 'page' ? null : ($isHome ? '/' : '/' . $slug),
|
||||
'path' => empty($page['layout_kind']) && in_array($page['page_type'] ?? 'page', ['page', 'home'], true)
|
||||
? ($root ? '/' : '/' . $slug) : null,
|
||||
'title' => $page['title'],
|
||||
'description' => $page['description'],
|
||||
'socialImage' => $showHero ? $page['image'] : '',
|
||||
@@ -116,7 +120,7 @@ final class SiteController
|
||||
}
|
||||
|
||||
$allPath = '/articles/feed/' . $slug . '/' . $key;
|
||||
$returnPath = ($slug === 'home' ? '/' : '/' . $slug) . '#' . $key;
|
||||
$returnPath = '/' . $slug . '#' . $key;
|
||||
$categoryLinks = [];
|
||||
foreach (array_keys($categories) as $value) {
|
||||
$categoryLinks[$value] = $allPath . '?category=' . rawurlencode((string) $value);
|
||||
@@ -190,8 +194,11 @@ final class SiteController
|
||||
$repo = new Repository();
|
||||
$xml = ['<?xml version="1.0" encoding="UTF-8"?>', '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'];
|
||||
$pages = $repo->pages(publishedOnly: true);
|
||||
if (in_array('home', array_column($pages, 'page_type'), true)) {
|
||||
$xml[] = $this->sitemapUrl('/', null);
|
||||
}
|
||||
foreach ($pages as $page) {
|
||||
$xml[] = $this->sitemapUrl($page['slug'] === 'home' ? '/' : '/' . $page['slug'], $page['updated_at']);
|
||||
$xml[] = $this->sitemapUrl('/' . $page['slug'], $page['updated_at']);
|
||||
}
|
||||
foreach ($repo->sitemapArticles() as $article) {
|
||||
$xml[] = $this->sitemapUrl('/articles/' . $article['slug'], $article['updated_at']);
|
||||
@@ -231,7 +238,8 @@ final class SiteController
|
||||
$entry = preg_match('~^/(?:admin|account)(?:/|$)~D', $normal)
|
||||
&& Route::dispatch($request->method(), $normal)[0] === Dispatcher::FOUND;
|
||||
$single = preg_match('~^/[a-z0-9]+(?:-[a-z0-9]+)*$~D', $normal);
|
||||
if ($entry || ($single && $normal !== '/home' && ((new Repository())->page(substr($normal, 1))['status'] ?? null) === 'published')
|
||||
$page = $single ? (new Repository())->page(substr($normal, 1)) : null;
|
||||
if ($entry || ($page && $page['layout_kind'] === null && in_array($page['page_type'], ['page', 'home'], true) && $page['status'] === 'published')
|
||||
|| preg_match('~^/articles(?:/[a-z0-9-]+){1,2}$~D', $normal)) {
|
||||
$query = $request->queryString();
|
||||
|
||||
|
||||
@@ -41,36 +41,28 @@ final class StudioController extends AdminController
|
||||
if (!isset($types[$data['type']]) || $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
throw new RuntimeException('请填写页面名称并选择页面类型。');
|
||||
}
|
||||
if (isset(SystemPage::TYPES[$data['type']])) {
|
||||
$type = $data['type'];
|
||||
$slug = 'system--' . $type . '-' . bin2hex(random_bytes(8));
|
||||
$maintenance = $type === 'maintenance';
|
||||
(new Repository())->createPage($slug, $data['name'], [
|
||||
'heading' => $maintenance ? '站点维护中' : '页面未找到',
|
||||
'lead' => $maintenance ? '我们正在维护站点,请稍后再访问。' : '你访问的页面可能已移动或删除。',
|
||||
'actions' => $maintenance ? [] : [['/', '返回首页', 'solid', false]],
|
||||
'visibility' => $maintenance ? ['header' => false, 'footer' => false] : [],
|
||||
], $type);
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $slug);
|
||||
}
|
||||
if (in_array($data['type'], ['header', 'footer'], true)) {
|
||||
$slug = LayoutPage::create($data['type'], $data['name']);
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $slug);
|
||||
}
|
||||
if (!$this->slug($data['slug']) || in_array($data['slug'], PageDraft::RESERVED, true)) {
|
||||
throw new RuntimeException('请填写页面名称及可用的网址标识。');
|
||||
}
|
||||
$slug = PageDraft::slug($data['slug']);
|
||||
$type = $data['type'];
|
||||
$key = $this->input($request, 'template');
|
||||
$template = $key === '' ? [] : PageTemplates::find($key);
|
||||
if ($template === null) {
|
||||
throw new RuntimeException('找不到所选整页模板。');
|
||||
}
|
||||
if ($key === '' && isset(SystemPage::TYPES[$type])) {
|
||||
$maintenance = $type === 'maintenance';
|
||||
$template = [
|
||||
'heading' => $maintenance ? '站点维护中' : '页面未找到',
|
||||
'lead' => $maintenance ? '我们正在维护站点,请稍后再访问。' : '你访问的页面可能已移动或删除。',
|
||||
'actions' => $maintenance ? [] : [['/', '返回首页', 'solid', false]],
|
||||
'visibility' => $maintenance ? ['header' => false, 'footer' => false] : [],
|
||||
];
|
||||
} elseif ($key === '' && in_array($type, ['header', 'footer'], true)) {
|
||||
$template['visibility'] = ['hero' => false];
|
||||
}
|
||||
$template['title'] = $data['name'];
|
||||
(new Repository())->createPage($data['slug'], $data['name'], $template);
|
||||
(new Repository())->createPage($slug, $data['name'], $template, $type);
|
||||
|
||||
return $this->success($request, '/admin/pages/' . $data['slug']);
|
||||
return $this->success($request, '/admin/pages/' . $slug);
|
||||
} catch (RuntimeException $error) {
|
||||
$data['error'] = $this->validationMessage($error);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ $e = View::escape(...);
|
||||
<nav class="admin-about-links" aria-label="项目链接">
|
||||
<?php foreach (['LaySite' => 'https://laysense.cn/laysite', 'Laysense' => 'https://laysense.cn'] as $name => $url): ?>
|
||||
<a href="<?= $e($url) ?>" target="_blank" rel="noopener noreferrer">
|
||||
<?= View::fragment('studio-icon', ['icon' => 'external']) ?><strong><?= $e($name) ?></strong><span><?= $e($url) ?></span>
|
||||
<?= View::fragment('studio-icon', ['icon' => 'external']) ?><strong><?= $e($name) ?></strong>
|
||||
</a>
|
||||
<?php endforeach ?>
|
||||
</nav>
|
||||
|
||||
@@ -5,14 +5,8 @@ use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$pageTypeLabels = LayoutPage::TYPES + SystemPage::TYPES;
|
||||
$regular = array_filter($pages, static fn (array $page): bool => $page['layout_kind'] === null && $page['page_type'] === 'page');
|
||||
$regular = array_filter($pages, static fn (array $page): bool => $page['layout_kind'] === null && in_array($page['page_type'], ['page', 'home'], true));
|
||||
$live = count(array_filter($regular, static fn (array $page): bool => $page['status'] === 'published'));
|
||||
$defaultSlugs = [];
|
||||
foreach (['header', 'footer'] as $kind) {
|
||||
if (isset($site[$kind . '_id'])) {
|
||||
$defaultSlugs[$kind] = LayoutPage::slug($kind, $site[$kind . '_id']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<header class="admin-heading dashboard-heading">
|
||||
<h1>网站后台</h1>
|
||||
@@ -35,6 +29,7 @@ foreach (['header', 'footer'] as $kind) {
|
||||
<option value="">全部页面</option>
|
||||
<option value="published">已发布</option>
|
||||
<option value="draft">草稿</option>
|
||||
<option value="home">首页</option>
|
||||
<option value="header">页头</option>
|
||||
<option value="footer">页脚</option>
|
||||
<?php foreach (SystemPage::TYPES as $type => $label): ?><option value="<?= $e($type) ?>"><?= $e($label) ?></option><?php endforeach ?>
|
||||
@@ -45,24 +40,24 @@ foreach (['header', 'footer'] as $kind) {
|
||||
<?php foreach ($pages as $page): ?>
|
||||
<?php
|
||||
$type = $page['page_type'];
|
||||
$kind = $page['layout_kind'] ?? (isset(SystemPage::TYPES[$type]) ? $type : null);
|
||||
$kind = $page['layout_kind'] ?? ($type !== 'page' ? $type : null);
|
||||
$label = $kind === null ? '' : ($pageTypeLabels[$kind] ?? '');
|
||||
$home = $page['slug'] === 'home';
|
||||
$path = $home ? '/' : '/' . $page['slug'];
|
||||
$home = $type === 'home';
|
||||
$path = '/' . $page['slug'];
|
||||
$deleteNote = '确定删除「' . $page['name'] . '」?此操作不可撤销。';
|
||||
if ($home) {
|
||||
$deleteNote .= '删除首页后,访问 / 将显示 404 页面。';
|
||||
$deleteNote .= '删除后,此页面将从首页候选中移除。';
|
||||
}
|
||||
$published = $page['status'] === 'published';
|
||||
$public = $kind === null && $published;
|
||||
$public = ($kind === null || $home) && $published;
|
||||
?>
|
||||
<li data-page-item="<?= $e($kind ?? $page['status']) ?>" data-page-label="<?= $e($page['name'] . ' ' . $page['title'] . ' ' . ($kind ? $label : $path)) ?>">
|
||||
<li data-page-item="<?= $e($kind ?? $page['status']) ?>" data-page-public-status="<?= $e($kind === null || $home ? $page['status'] : '') ?>" data-page-label="<?= $e($page['name'] . ' ' . $page['title'] . ' ' . ($kind ? $label : $path)) ?>">
|
||||
<div class="dashboard-page-label"><strong><?= $e($page['name']) ?></strong>
|
||||
<?php if ($kind === null): ?><small><?= $e($path) ?></small>
|
||||
<?php elseif (($defaultSlugs[$kind] ?? null) === $page['slug']): ?><small>站点默认</small>
|
||||
<?php if ($kind === null || $home): ?><small><?= $home ? '/ · ' : '' ?><?= $e($path) ?></small>
|
||||
<?php elseif ($page['layout_id'] !== null && ($site[$kind . '_id'] ?? null) === $page['layout_id']): ?><small>站点默认</small>
|
||||
<?php elseif (($site['system_pages'][$kind] ?? null) === $page['slug']): ?><small><?= $kind === 'maintenance' ? ($site['maintenance_enabled'] ? '维护模式已开启' : '已选作维护页') : '已启用为 404 页' ?></small><?php endif ?>
|
||||
</div>
|
||||
<span class="dashboard-page-state" data-published="<?= !$page['layout_kind'] && $published ? 'true' : 'false' ?>"><?= $kind ? $e($label) : ($published ? '已发布' : '草稿') ?><?= isset(SystemPage::TYPES[$type]) ? ($published ? ' · 已发布' : ' · 草稿') : '' ?></span>
|
||||
<span class="dashboard-page-state" data-published="<?= !$page['layout_kind'] && $published ? 'true' : 'false' ?>"><?= $kind ? $e($label) : ($published ? '已发布' : '草稿') ?><?= ($home || isset(SystemPage::TYPES[$type])) ? ($published ? ' · 已发布' : ' · 草稿') : '' ?></span>
|
||||
<div class="dashboard-page-actions">
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($page['slug']) ?>"><?= View::fragment('studio-icon', ['icon' => 'edit']) ?>编辑页面</a>
|
||||
<?= View::fragment('admin-view-link', [
|
||||
|
||||
@@ -17,6 +17,7 @@ $e = View::escape(...);
|
||||
<ul class="admin-list">
|
||||
<?php foreach ($items as $item): ?>
|
||||
<li><div class="palette-name"><strong><?= $e($item['name']) ?></strong>
|
||||
<?php if ($item['id'] === $defaultPaletteId): ?><span class="dashboard-page-state">站点默认</span><?php endif ?>
|
||||
<?= View::fragment('palette-swatches', ['colors' => $item['colors']]) ?>
|
||||
</div>
|
||||
<a class="button button-outline" href="/admin/design/palette/<?= $e($item['id']) ?>"><?= View::fragment('studio-icon', ['icon' => 'edit']) ?>编辑</a>
|
||||
|
||||
@@ -33,7 +33,7 @@ $active = match (true) {
|
||||
<?php endif ?>
|
||||
<?php if (!empty($pageTemplateDrawer)): ?>
|
||||
<link rel="stylesheet" href="/assets/page-template-drawer.css">
|
||||
<script src="/assets/page-template-drawer.js" defer></script>
|
||||
<script src="/assets/page-template-drawer.js?v=<?= $e($laysiteVersion) ?>" defer></script>
|
||||
<?php endif ?>
|
||||
<?php if (!empty($canvasSourceEditor) || !empty($headEditor)): ?>
|
||||
<link rel="stylesheet" href="/assets/vendor/codemirror/codemirror.min.css">
|
||||
|
||||
+31
-10
@@ -9,10 +9,17 @@ use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$slug = $page['slug'];
|
||||
$path = $slug === 'home' ? '/' : '/' . $slug;
|
||||
$path = '/' . $slug;
|
||||
$home = $page['page_type'] === 'home';
|
||||
$pageTypes = LayoutPage::TYPES + SystemPage::TYPES;
|
||||
$layoutSlugs = array_column($designs, 'slug', 'id');
|
||||
$published = $page['status'] === 'published';
|
||||
$publicPage = !$page['layout_kind'] && $page['page_type'] === 'page';
|
||||
$paletteOptions = [['id' => '', 'name' => '页面原有配色', 'colors' => []], ...$palettes];
|
||||
$publicPage = !$page['layout_kind'] && in_array($page['page_type'], ['page', 'home'], true);
|
||||
$defaultPalette = empty($page['theme']) ? (array_column($palettes, null, 'id')[$defaultPaletteId] ?? null) : null;
|
||||
$paletteOptions = [[
|
||||
'id' => '', 'name' => $defaultPalette ? '站点默认 · ' . $defaultPalette['name'] : '模板原有配色',
|
||||
'colors' => $defaultPalette['colors'] ?? [], 'version' => $defaultPalette['version'] ?? 0, 'cssId' => $defaultPalette['id'] ?? null,
|
||||
], ...$palettes];
|
||||
$previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
$systemLabel = SystemPage::TYPES[$page['page_type']] ?? null;
|
||||
$fontSizes = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 48, 56, 64, 72, 96, 120, 144];
|
||||
@@ -22,15 +29,18 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<header class="admin-heading">
|
||||
<div><h1 data-page-editor-title><?= $e($title) ?></h1><p class="studio-page-meta">
|
||||
<?php if ($layout): ?><span class="dashboard-page-state"><?= $e(LayoutPage::TYPES[$layout['kind']]) ?></span>
|
||||
<?php else: ?><?php if ($systemLabel): ?><span><?= $e($systemLabel) ?></span><?php else: ?><code><?= $e($path) ?></code><?php endif ?><span class="dashboard-page-state" data-page-publication data-published="<?= $published ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span><?php endif ?>
|
||||
<?php else: ?><?php if ($systemLabel || $home): ?><span><?= $e($home ? '首页' : $systemLabel) ?></span><?php else: ?><code><?= $e($path) ?></code><?php endif ?><span class="dashboard-page-state" data-page-publication data-published="<?= $published ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span><?php endif ?>
|
||||
</p></div>
|
||||
<div class="actions">
|
||||
<a class="button button-outline" href="#studio-page-settings"><?= View::fragment('studio-icon', ['icon' => 'settings']) ?>页面设置</a>
|
||||
<?php if (!$layout): ?>
|
||||
<?php foreach (['header' => '编辑页头', 'footer' => '编辑页脚'] as $kind => $label): ?>
|
||||
<?php $defaultId = $layoutDefaults[$kind . '_id'] ?? ''; $id = $page[$kind . '_id'] ?? $defaultId; ?>
|
||||
<a class="button button-outline" data-page-layout-editor="<?= $e($kind) ?>" data-default-id="<?= $e($defaultId) ?>"
|
||||
href="<?= $id ? '/admin/pages/' . $e(LayoutPage::slug($kind, $id)) : '/admin/new-page?type=' . $e($kind) ?>" target="_blank" rel="noopener noreferrer"<?= !($page['visibility'][$kind] ?? true) ? ' hidden' : '' ?>><?= View::fragment('studio-icon', ['icon' => $kind]) ?><?= $e($label) ?></a>
|
||||
<?php
|
||||
$defaultId = $layoutDefaults[$kind . '_id'] ?? null;
|
||||
$layoutSlug = $layoutSlugs[$page[$kind . '_id'] ?? $defaultId] ?? '';
|
||||
?>
|
||||
<a class="button button-outline" data-page-layout-editor="<?= $e($kind) ?>" data-default-slug="<?= $e($layoutSlugs[$defaultId] ?? '') ?>"
|
||||
href="<?= $layoutSlug ? '/admin/pages/' . $e($layoutSlug) : '/admin/new-page?type=' . $e($kind) ?>" target="_blank" rel="noopener noreferrer"<?= !($page['visibility'][$kind] ?? true) ? ' hidden' : '' ?>><?= View::fragment('studio-icon', ['icon' => $kind]) ?><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
<button type="button" class="button button-outline" data-open-page-templates hidden><?= View::fragment('studio-icon', ['icon' => 'templates']) ?>整页模板</button>
|
||||
<?php if ($systemLabel): ?><a class="button button-outline" href="/admin/settings"><?= View::fragment('studio-icon', ['icon' => 'settings']) ?>站点设置</a>
|
||||
@@ -229,14 +239,24 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<button class="button button-outline" type="button" disabled data-hero-control="image">首屏图片</button>
|
||||
<button class="button button-outline" type="button" disabled data-hero-control="add-action">添加首屏按钮</button>
|
||||
<button class="button button-outline" type="button" disabled data-hero-control="navigation">本页目录</button>
|
||||
<?php if (!$layout && !$systemLabel && $slug !== 'home'): ?><button class="button button-outline" type="button" disabled data-hero-control="breadcrumbs">面包屑路径</button><?php endif ?>
|
||||
<?php if (!$layout && !$systemLabel && !$home): ?><button class="button button-outline" type="button" disabled data-hero-control="breadcrumbs">面包屑路径</button><?php endif ?>
|
||||
</div>
|
||||
</details>
|
||||
<div class="studio-settings-grid">
|
||||
<div class="studio-settings-content">
|
||||
<label>页面名称<input name="name" value="<?= $e($page['name']) ?>" required maxlength="100"></label>
|
||||
<div class="form-grid">
|
||||
<label>网址标识<input name="page_slug" value="<?= $e($slug) ?>" required maxlength="70"></label>
|
||||
<label>页面类型<select name="page_type">
|
||||
<?php foreach ($pageTypes as $type => $label): ?>
|
||||
<option value="<?= $e($type) ?>"<?= ($page['layout_kind'] ?? $page['page_type']) === $type ? ' selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
</div>
|
||||
<?php if ($layout || $systemLabel): ?><p class="field-note">转为普通页面或首页后需重新发布。</p><?php endif ?>
|
||||
<?php if ($layout): ?>
|
||||
<input type="hidden" name="title" value="<?= $e($page['title']) ?>">
|
||||
<input type="hidden" name="description" value="<?= $e($page['description']) ?>">
|
||||
<?php if ($layoutDefault && $layoutBase): ?>
|
||||
<p class="field-note">当前站点默认<?= $e(LayoutPage::TYPES[$layout['kind']]) ?></p>
|
||||
<?php else: ?>
|
||||
@@ -260,7 +280,7 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<option value=""<?= $visible && $page[$kind . '_id'] === null ? ' selected' : '' ?>>站点默认</option>
|
||||
<?php foreach ($designs as $item): ?>
|
||||
<?php if ($item['kind'] !== $kind) continue; ?>
|
||||
<option value="<?= $e($item['id']) ?>"<?= $visible && $page[$kind . '_id'] === $item['id'] ? ' selected' : '' ?>><?= $e($item['name']) ?></option>
|
||||
<option value="<?= $e($item['id']) ?>" data-layout-slug="<?= $e($item['slug']) ?>"<?= $visible && $page[$kind . '_id'] === $item['id'] ? ' selected' : '' ?>><?= $e($item['name']) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<?php endforeach ?>
|
||||
@@ -268,7 +288,8 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];
|
||||
<label for="page-palette">配色方案</label>
|
||||
<select id="page-palette" name="palette_id">
|
||||
<?php foreach ($paletteOptions as $option): ?>
|
||||
<option value="<?= $e($option['id']) ?>"<?= (string) $page['palette_id'] === (string) $option['id'] ? ' selected' : '' ?>><?= $e($option['name']) ?></option>
|
||||
<?php $cssId = $option['cssId'] ?? $option['id']; ?>
|
||||
<option value="<?= $e($option['id']) ?>" data-palette-css="<?= $cssId ? '/palette/' . $e($cssId) . '.css?v=' . $e($option['version']) : '' ?>"<?= (string) $page['palette_id'] === (string) $option['id'] ? ' selected' : '' ?>><?= $e($option['name']) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
<details class="palette-picker" hidden>
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ if (str_starts_with($imageUrl, '/')) {
|
||||
$imageUrl = View::absolute($imageUrl);
|
||||
}
|
||||
$theme = $page['theme'] ?? '';
|
||||
$palette = DesignLibrary::find((int) ($page['palette_id'] ?? 0), 'palette');
|
||||
$palette = DesignLibrary::find((int) ($page['palette_id'] ?? ($theme === '' ? $site['palette_id'] ?? 0 : 0)), 'palette');
|
||||
$showHeader = $page['visibility']['header'] ?? true;
|
||||
$showFooter = $page['visibility']['footer'] ?? true;
|
||||
$canvasStyles = $content . ($headerMarkup ?? '') . ($footerMarkup ?? '');
|
||||
|
||||
+2
-2
@@ -5,9 +5,9 @@ use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$home = $page['slug'] === 'home';
|
||||
$home = ($page['page_type'] ?? 'page') === 'home';
|
||||
$shared = !empty($page['layout_kind']);
|
||||
$system = ($page['page_type'] ?? 'page') !== 'page';
|
||||
$system = !in_array($page['page_type'] ?? 'page', ['page', 'home'], true);
|
||||
$showHero = $page['visibility']['hero'] ?? true;
|
||||
$heroLinks = array_filter($page['sections'], static fn (array $section): bool => $section['style'] === 'hero-links');
|
||||
$alignments = $page['alignments'];
|
||||
|
||||
@@ -17,8 +17,8 @@ $e = View::escape(...);
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<label>页面名称<input name="name" maxlength="100" value="<?= $e($name) ?>" required></label>
|
||||
<label data-new-page-slug<?= $type !== 'page' ? ' hidden' : '' ?>>网址标识<input name="slug" maxlength="70" value="<?= $e($slug) ?>" pattern="[a-z0-9]+(-[a-z0-9]+)*" placeholder="my-page"<?= $type === 'page' ? ' required' : ' disabled' ?>>
|
||||
<small>创建后为草稿。网址标识为 home 的普通页面发布后会显示在首页(/)。</small>
|
||||
<label>网址标识<input name="slug" maxlength="70" value="<?= $e($slug) ?>" pattern="[a-z0-9]+(-[a-z0-9]+)*" placeholder="my-page" required>
|
||||
<small>普通页面和首页使用该标识作为访问路径。</small>
|
||||
</label>
|
||||
<div class="form-submit"><button type="submit" class="button button-primary"><?= View::fragment('studio-icon', ['icon' => 'add']) ?>创建页面</button></div>
|
||||
</form>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\PageTemplates;
|
||||
use App\Content\SystemPage;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
@@ -50,10 +52,15 @@ $previewRoot = '/assets/page-templates/';
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<input type="hidden" name="template">
|
||||
<div class="form-grid">
|
||||
<label>页面类型<select name="type">
|
||||
<?php foreach (LayoutPage::TYPES + SystemPage::TYPES as $type => $label): ?>
|
||||
<option value="<?= $e($type) ?>"><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<label>页面名称<input name="name" maxlength="100" required></label>
|
||||
<label>网址标识<input name="slug" maxlength="70" pattern="[a-z0-9]+(-[a-z0-9]+)*" required></label>
|
||||
</div>
|
||||
<div class="form-submit"><button type="submit" class="button button-primary"><?= View::fragment('studio-icon', ['icon' => 'add']) ?>用此模板创建草稿</button></div>
|
||||
<div class="form-submit"><button type="submit" class="button button-primary"><?= View::fragment('studio-icon', ['icon' => 'add']) ?>使用此模板</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user