forked from laysense/laysite
Add maintenance and 404 pages, template suites, and MCP skill
This commit is contained in:
@@ -323,7 +323,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 && $data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
(!$layout && $page['page_type'] === 'page' && $data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
(($data['visibility']['hero'] ?? true) && $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'] < 10 || $data['image_scale'] > 100)) ||
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Content\DesignFieldError;
|
||||
use App\Content\DesignLibrary;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\SystemPage;
|
||||
use App\Http\Request;
|
||||
use RuntimeException;
|
||||
use support\Response;
|
||||
@@ -76,10 +77,13 @@ final class DesignController extends AdminController
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$site = (new Repository())->site();
|
||||
$repo = new Repository();
|
||||
$site = $repo->site();
|
||||
$error = '';
|
||||
$name = $site['name'];
|
||||
$cdn = $site['cdn']['origin'] ?? '';
|
||||
$systemPages = $site['system_pages'] ?? [];
|
||||
$maintenance = $site['maintenance_enabled'] ?? false;
|
||||
$version = (int) ($site['revisions']['general'] ?? 0);
|
||||
if ($request->method() === 'POST') {
|
||||
try {
|
||||
@@ -88,7 +92,12 @@ final class DesignController extends AdminController
|
||||
if ($name === '' || mb_strlen($name) > 100) {
|
||||
throw new RuntimeException('站点名称必须为 1 至 100 个字符。');
|
||||
}
|
||||
SiteDesign::saveGeneral($name, $cdn, $this->version($request));
|
||||
$systemPages = array_filter([
|
||||
'maintenance' => $this->input($request, 'maintenance_page'),
|
||||
'not-found' => $this->input($request, 'not_found_page'),
|
||||
], static fn (string $slug): bool => $slug !== '');
|
||||
$maintenance = $request->post('maintenance_enabled') === '1';
|
||||
SiteDesign::saveGeneral($name, $cdn, $this->version($request), $systemPages, $maintenance);
|
||||
|
||||
return $this->success($request, '/admin/settings?saved=1');
|
||||
} catch (RuntimeException $ex) {
|
||||
@@ -96,8 +105,16 @@ final class DesignController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
$systemChoices = [];
|
||||
foreach ($repo->pages() as $page) {
|
||||
$type = $page['page_type'];
|
||||
if (isset(SystemPage::TYPES[$type]) && $page['status'] === 'published') {
|
||||
$systemChoices[$type][$page['slug']] = $page['name'];
|
||||
}
|
||||
}
|
||||
return $this->render($request, 'studio-settings', [
|
||||
'title' => '站点设置', 'name' => $name, 'cdn' => $cdn, 'version' => $version, 'error' => $error,
|
||||
'systemPages' => $systemPages, 'systemChoices' => $systemChoices, 'maintenance' => $maintenance,
|
||||
'saved' => $request->get('saved') === '1',
|
||||
], $error === '' ? 200 : 422);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ final class McpController
|
||||
try {
|
||||
$data = match ($name) {
|
||||
'list_pages' => $repo->pages(),
|
||||
'get_page' => $this->read($repo, PageDraft::slug($args['slug'] ?? null, [], includeLayouts: true)),
|
||||
'get_page' => $this->read($repo, PageDraft::slug($args['slug'] ?? null, [], includeSpecial: true)),
|
||||
'list_templates' => $this->templates(),
|
||||
'list_designs' => DesignLibrary::all(),
|
||||
'create_draft' => $this->create($repo, $args),
|
||||
|
||||
@@ -25,7 +25,8 @@ final class SiteController
|
||||
{
|
||||
$repo = new Repository();
|
||||
$page = $repo->page($slug);
|
||||
if (!$page || $page['layout_kind'] !== null || $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
|
||||
if (!$page || $page['layout_kind'] !== null || $page['page_type'] !== 'page'
|
||||
|| $page['status'] !== 'published' || $slug === 'home' && $request->path() !== '/') {
|
||||
return $this->missing($request);
|
||||
}
|
||||
if ($slug === 'articles' && $request->get('page') !== null) {
|
||||
@@ -41,7 +42,7 @@ final class SiteController
|
||||
return $this->renderPage($repo, $page);
|
||||
}
|
||||
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false, bool $canvas = false): Response
|
||||
public function renderPage(Repository $repo, array $page, bool $preview = false, bool $canvas = false, int $status = 200): Response
|
||||
{
|
||||
$slug = $page['slug'];
|
||||
$isHome = $slug === 'home';
|
||||
@@ -51,13 +52,13 @@ final class SiteController
|
||||
return View::render('page', [
|
||||
'site' => $repo->site(),
|
||||
'page' => $page,
|
||||
'path' => $isHome ? '/' : '/' . $slug,
|
||||
'path' => ($page['page_type'] ?? 'page') !== 'page' ? null : ($isHome ? '/' : '/' . $slug),
|
||||
'title' => $page['title'],
|
||||
'description' => $page['description'],
|
||||
'socialImage' => $showHero ? $page['image'] : '',
|
||||
'socialAlt' => $showHero ? $page['alt'] : '',
|
||||
'previewMode' => $preview, 'canvas' => $preview && $canvas, 'noindex' => $preview,
|
||||
]);
|
||||
'previewMode' => $preview, 'canvas' => $preview && $canvas, 'noindex' => $preview || $status >= 400,
|
||||
], $status);
|
||||
}
|
||||
|
||||
public function archive(Request $request, ?string $category = null, ?string $tag = null): Response
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Content\Media;
|
||||
use App\Content\PageDraft;
|
||||
use App\Content\PageTemplates;
|
||||
use App\Content\Repository;
|
||||
use App\Content\SystemPage;
|
||||
use App\Http\Request;
|
||||
use RuntimeException;
|
||||
use support\Response;
|
||||
@@ -24,21 +25,36 @@ final class StudioController extends AdminController
|
||||
if ($failure = $this->guard($request)) {
|
||||
return $failure;
|
||||
}
|
||||
$types = LayoutPage::TYPES + SystemPage::TYPES;
|
||||
$type = $request->get('type');
|
||||
$data = [
|
||||
'title' => '新建页面', 'name' => '', 'slug' => '', 'error' => '', 'pageTemplateDrawer' => true,
|
||||
'openTemplates' => $request->get('templates') === '1',
|
||||
'type' => is_string($type) && isset(LayoutPage::TYPES[$type]) ? $type : 'page',
|
||||
'type' => is_string($type) && isset($types[$type]) ? $type : 'page',
|
||||
'types' => $types,
|
||||
];
|
||||
if ($request->method() === 'POST') {
|
||||
$data['name'] = $this->input($request, 'name');
|
||||
$data['slug'] = $this->input($request, 'slug');
|
||||
$data['type'] = $request->post('type') === null ? 'page' : $this->input($request, 'type');
|
||||
try {
|
||||
if (!isset(LayoutPage::TYPES[$data['type']]) || $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
if (!isset($types[$data['type']]) || $data['name'] === '' || mb_strlen($data['name']) > 100) {
|
||||
throw new RuntimeException('请填写页面名称并选择页面类型。');
|
||||
}
|
||||
if ($data['type'] !== 'page') {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user