forked from laysense/laysite
Add maintenance and 404 pages, template suites, and MCP skill
This commit is contained in:
@@ -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