forked from laysense/laysense.cn
Expand page templates and configure page visibility
This commit is contained in:
@@ -272,6 +272,18 @@ class AdminController
|
||||
}
|
||||
$page = array_replace($page, $data, ['version' => $this->version($request)]);
|
||||
try {
|
||||
$data['visibility'] = $page['visibility'];
|
||||
foreach (['hero', 'header', 'footer'] as $area) {
|
||||
$value = $request->post('show_' . $area);
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
if (!in_array($value, ['0', '1'], true)) {
|
||||
throw new RuntimeException('页面显示选项不正确。');
|
||||
}
|
||||
$data['visibility'][$area] = $value === '1';
|
||||
}
|
||||
$page['visibility'] = $data['visibility'];
|
||||
$data['alignments'] = $request->post('alignments') === null ? $page['alignments']
|
||||
: $this->alignmentMap(json_decode($this->input($request, 'alignments'), true), ['heading', 'lead', 'actions', 'image']);
|
||||
$page['alignments'] = $data['alignments'];
|
||||
@@ -279,7 +291,7 @@ class AdminController
|
||||
if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true)
|
||||
|| $data['title'] === '' || mb_strlen($data['title']) > 160 ||
|
||||
($data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 ||
|
||||
$data['heading'] === '' || mb_strlen($data['heading'] . $data['accent']) > 110 ||
|
||||
(($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)) ||
|
||||
strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true)) || !$validButtons) {
|
||||
@@ -365,8 +377,8 @@ class AdminController
|
||||
throw new RuntimeException('区块已变更或画布内容无效,请重新打开编辑页。');
|
||||
}
|
||||
if ($delete) {
|
||||
if ($isNew || empty($available[$key]['feed'])) {
|
||||
throw new RuntimeException('此区块不能通过模块工具删除。');
|
||||
if ($isNew) {
|
||||
throw new RuntimeException('未保存的区块无需提交删除。');
|
||||
}
|
||||
$updates[$key] = compact('key', 'version', 'delete');
|
||||
continue;
|
||||
|
||||
@@ -41,6 +41,7 @@ final class SiteController
|
||||
{
|
||||
$slug = $page['slug'];
|
||||
$isHome = $slug === 'home';
|
||||
$showHero = $page['visibility']['hero'] ?? true;
|
||||
$categories = $repo->categories();
|
||||
foreach ($page['sections'] as &$section) {
|
||||
if (!$section['feed']) {
|
||||
@@ -75,8 +76,8 @@ final class SiteController
|
||||
'path' => $isHome ? '/' : '/' . $slug,
|
||||
'title' => $page['title'],
|
||||
'description' => $page['description'],
|
||||
'socialImage' => $page['image'],
|
||||
'socialAlt' => $page['alt'],
|
||||
'socialImage' => $showHero ? $page['image'] : '',
|
||||
'socialAlt' => $showHero ? $page['alt'] : '',
|
||||
'previewMode' => $preview, 'canvas' => $preview && $canvas, 'noindex' => $preview,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user