Prepare LaySite 1.5.1 page routing and template updates

This commit is contained in:
2026-11-28 03:07:14 +08:00
parent 50fb30ff3b
commit 474cb766be
41 changed files with 354 additions and 146 deletions
+1 -1
View File
@@ -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>
+11 -16
View File
@@ -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', [
+1
View File
@@ -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>
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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'];
+2 -2
View File
@@ -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>
+8 -1
View File
@@ -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>