forked from laysense/laysite
Add maintenance and 404 pages, template suites, and MCP skill
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\SystemPage;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$regular = array_filter($pages, static fn (array $page): bool => $page['layout_kind'] === null);
|
||||
$regular = array_filter($pages, static fn (array $page): bool => $page['layout_kind'] === null && $page['page_type'] === 'page');
|
||||
$live = count(array_filter($regular, static fn (array $page): bool => $page['status'] === 'published'));
|
||||
$defaultSlugs = [];
|
||||
foreach (['header', 'footer'] as $kind) {
|
||||
@@ -24,31 +25,40 @@ foreach (['header', 'footer'] as $kind) {
|
||||
<section class="admin-panel dashboard-pages" aria-labelledby="pages-title" data-page-list>
|
||||
<div class="admin-heading compact">
|
||||
<h2 id="pages-title">网站页面</h2>
|
||||
<p class="field-note"><?= $live ?> 个已发布 · <?= count($regular) - $live ?> 个草稿 · <?= count($pages) - count($regular) ?> 个页头页脚</p>
|
||||
<p class="field-note"><?= $live ?> 个已发布 · <?= count($regular) - $live ?> 个草稿 · <?= count($pages) - count($regular) ?> 个特殊页面</p>
|
||||
</div>
|
||||
<div class="dashboard-filters" data-page-filters hidden>
|
||||
<label>查找页面<input type="search" data-page-search placeholder="页面名称或地址"></label>
|
||||
<label>发布状态<select data-page-status>
|
||||
<option value="">全部状态</option>
|
||||
<label>状态或类型<select data-page-status>
|
||||
<option value="">全部页面</option>
|
||||
<option value="published">已发布</option>
|
||||
<option value="draft">草稿</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 ?>
|
||||
</select></label>
|
||||
</div>
|
||||
<p class="empty-state" data-page-empty role="status"<?= $pages ? ' hidden' : '' ?>><?= $pages ? '没有匹配的页面。' : '暂无页面。' ?></p>
|
||||
<ul class="admin-list dashboard-page-list">
|
||||
<?php foreach ($pages as $page): ?>
|
||||
<?php $kind = $page['layout_kind']; $path = $page['slug'] === 'home' ? '/' : '/' . $page['slug']; $published = $kind === null && $page['status'] === 'published'; ?>
|
||||
<li data-page-item="<?= $e($kind ?? $page['status']) ?>" data-page-label="<?= $e($page['name'] . ' ' . $page['title'] . ' ' . ($kind ? LayoutPage::TYPES[$kind] : $path)) ?>">
|
||||
<?php
|
||||
$type = $page['page_type'];
|
||||
$kind = $page['layout_kind'] ?? (isset(SystemPage::TYPES[$type]) ? $type : null);
|
||||
$label = (LayoutPage::TYPES + SystemPage::TYPES)[$kind] ?? '';
|
||||
$path = $page['slug'] === 'home' ? '/' : '/' . $page['slug'];
|
||||
$published = $page['status'] === 'published';
|
||||
$public = $kind === null && $published;
|
||||
?>
|
||||
<li data-page-item="<?= $e($kind ?? $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): ?><small><?= $e($path) ?></small>
|
||||
<?php elseif (($defaultSlugs[$kind] ?? null) === $page['slug']): ?><small>站点默认</small><?php endif ?>
|
||||
<?php elseif (($defaultSlugs[$kind] ?? null) === $page['slug']): ?><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="<?= $published ? 'true' : 'false' ?>"><?= $kind ? $e(LayoutPage::TYPES[$kind]) : ($published ? '已发布' : '草稿') ?></span>
|
||||
<span class="dashboard-page-state" data-published="<?= !$page['layout_kind'] && $published ? 'true' : 'false' ?>"><?= $kind ? $e($label) : ($published ? '已发布' : '草稿') ?><?= isset(SystemPage::TYPES[$type]) ? ($published ? ' · 已发布' : ' · 草稿') : '' ?></span>
|
||||
<div class="dashboard-page-actions">
|
||||
<a class="button button-outline" href="/admin/pages/<?= $e($page['slug']) ?>">编辑页面</a>
|
||||
<a href="<?= $e($published ? $path : '/admin/pages/' . $page['slug'] . '/preview') ?>" target="_blank" rel="noopener"><?= $published ? '查看' : '预览' ?></a>
|
||||
<a href="<?= $e($public ? $path : '/admin/pages/' . $page['slug'] . '/preview') ?>" target="_blank" rel="noopener"><?= $public ? '查看' : '预览' ?></a>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
|
||||
@@ -66,6 +66,7 @@ $active = match (true) {
|
||||
</div>
|
||||
</header>
|
||||
<main class="admin-wrap admin-main<?= !empty($wideAdmin) ? ' admin-wide' : '' ?>" id="admin-content"><?= $content ?></main>
|
||||
<footer class="admin-wrap admin-version">LaySite ver <?= $e(trim(file_get_contents(dirname(__DIR__, 2) . '/VERSION'))) ?></footer>
|
||||
<?php if ($user): ?>
|
||||
<dialog class="media-picker" id="media-picker" aria-labelledby="picker-heading">
|
||||
<header class="admin-heading compact"><h2 id="picker-heading">从媒体库选择</h2><button class="button button-outline" type="button" data-close-picker>关闭</button></header>
|
||||
|
||||
@@ -4,18 +4,20 @@ use App\Content\CanvasStyle;
|
||||
use App\Content\Database;
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\SystemPage;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
$slug = $page['slug'];
|
||||
$path = $slug === 'home' ? '/' : '/' . $slug;
|
||||
$previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
$systemLabel = SystemPage::TYPES[$page['page_type']] ?? null;
|
||||
?>
|
||||
<a class="back-link" href="/admin">返回页面</a>
|
||||
<header class="admin-heading">
|
||||
<div><h1><?= $e($title) ?></h1><p class="studio-page-meta">
|
||||
<?php if ($layout): ?><span class="dashboard-page-state"><?= $e(LayoutPage::TYPES[$layout['kind']]) ?></span>
|
||||
<?php else: ?><code><?= $e($path) ?></code><span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span><?php endif ?>
|
||||
<?php else: ?><?php if ($systemLabel): ?><span><?= $e($systemLabel) ?></span><?php else: ?><code><?= $e($path) ?></code><?php endif ?><span class="dashboard-page-state" data-published="<?= $page['status'] === 'published' ? 'true' : 'false' ?>"><?= $page['status'] === 'draft' ? '草稿' : '已发布' ?></span><?php endif ?>
|
||||
</p></div>
|
||||
<div class="actions">
|
||||
<a class="button button-outline" href="#studio-page-settings">页面设置</a>
|
||||
@@ -26,7 +28,8 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
href="<?= $id ? '/admin/pages/' . $e(LayoutPage::slug($kind, $id)) : '/admin/new-page?type=' . $e($kind) ?>" target="_blank" rel="noopener"<?= !($page['visibility'][$kind] ?? true) ? ' hidden' : '' ?>><?= $e($label) ?></a>
|
||||
<?php endforeach ?>
|
||||
<button type="button" class="button button-outline" data-open-page-templates hidden>整页模板</button>
|
||||
<?php if ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
|
||||
<?php if ($systemLabel): ?><a class="button button-outline" href="/admin/settings">站点设置</a>
|
||||
<?php elseif ($page['status'] === 'published'): ?><a class="button button-outline" href="<?= $e($path) ?>">公开页面</a><?php endif ?>
|
||||
<?php endif ?>
|
||||
<a class="button button-outline" href="<?= $e($previewUrl) ?>" target="_blank" rel="noopener">打开预览</a>
|
||||
</div>
|
||||
|
||||
@@ -22,5 +22,6 @@ $brand = $data['brand'] ?: $site['name'];
|
||||
<small><?= $e($data['legal']) ?></small>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
<small class="site-footer-credit">Powered by <a href="https://laysense.cn/laysite">LaySite</a></small>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ use App\Content\View;
|
||||
$e = View::escape(...);
|
||||
$home = $page['slug'] === 'home';
|
||||
$shared = !empty($page['layout_kind']);
|
||||
$system = ($page['page_type'] ?? 'page') !== 'page';
|
||||
$showHero = $page['visibility']['hero'] ?? true;
|
||||
$heroLinks = array_filter($page['sections'], static fn (array $section): bool => $section['style'] === 'hero-links');
|
||||
$alignments = $page['alignments'];
|
||||
@@ -22,7 +23,7 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
|
||||
<?php if ($showHero || $canvas): ?>
|
||||
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>"<?= $canvas ? ' data-studio-hero-content' : '' ?><?= $showHero ? '' : ' hidden' ?>>
|
||||
<div class="hero-copy">
|
||||
<?php if (!$home && !$shared): ?>
|
||||
<?php if (!$home && !$shared && !$system): ?>
|
||||
<nav class="breadcrumbs" aria-label="面包屑" itemscope itemtype="https://schema.org/BreadcrumbList">
|
||||
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
|
||||
<a itemprop="item" href="/"><span itemprop="name">首页</span></a>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
use App\Content\LayoutPage;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
@@ -13,7 +12,7 @@ $e = View::escape(...);
|
||||
<form class="admin-form admin-panel" method="post" action="/admin/new-page">
|
||||
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
||||
<label>页面类型<select name="type" data-new-page-type>
|
||||
<?php foreach (LayoutPage::TYPES as $value => $label): ?>
|
||||
<?php foreach ($types as $value => $label): ?>
|
||||
<option value="<?= $e($value) ?>" <?= $type === $value ? 'selected' : '' ?>><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
|
||||
@@ -11,5 +11,21 @@ $e = View::escape(...);
|
||||
<input type="hidden" name="version" value="<?= $e($version) ?>">
|
||||
<label>站点名称<input name="name" value="<?= $e($name) ?>" maxlength="100" required></label>
|
||||
<label>静态资源 CDN<input name="cdn" value="<?= $e($cdn) ?>" placeholder="https://cdn.example.com"><small>填写后,公开页面的 /assets/ 文件从该地址加载。</small></label>
|
||||
<fieldset class="settings-stack">
|
||||
<legend>系统页面</legend>
|
||||
<?php foreach (['maintenance' => ['maintenance_page', '维护页', '选择已发布的维护页'], 'not-found' => ['not_found_page', '404 页', '使用系统 404 页']] as $type => [$field, $label, $placeholder]): ?>
|
||||
<label><?= $e($label) ?><select name="<?= $e($field) ?>">
|
||||
<option value=""><?= $e($placeholder) ?></option>
|
||||
<?php foreach ($systemChoices[$type] ?? [] as $slug => $name): ?>
|
||||
<option value="<?= $e($slug) ?>"<?= ($systemPages[$type] ?? null) === $slug ? ' selected' : '' ?>><?= $e($name) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<?php if (empty($systemChoices[$type])): ?>
|
||||
<a class="back-link" href="/admin/new-page?type=<?= $e($type) ?>">新建<?= $e($label) ?></a>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
<label><input type="checkbox" name="maintenance_enabled" value="1"<?= $maintenance ? ' checked' : '' ?>> 开启维护模式</label>
|
||||
<p class="field-note">开启后,访客会看到维护页。后台仍可登录和编辑。</p>
|
||||
</fieldset>
|
||||
<button type="submit" class="button button-primary">保存设置</button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user