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
+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', [