Expand page templates and configure page visibility

This commit is contained in:
2026-11-22 12:54:01 +08:00
parent 931d333ca7
commit f23c3b95ba
27 changed files with 293 additions and 44 deletions
+10
View File
@@ -122,6 +122,16 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<label>页面名称<input name="name" value="<?= $e($page['name']) ?>" required maxlength="100"></label>
<label>SEO 标题<input name="title" value="<?= $e($page['title']) ?>" required maxlength="160"></label>
<label>SEO 描述<textarea name="description" rows="2" maxlength="300"><?= $e($page['description']) ?></textarea></label>
<fieldset class="admin-options form-grid">
<legend>页面显示</legend>
<?php foreach (['header' => '页头', 'hero' => '首屏', 'footer' => '页脚'] as $area => $label): ?>
<?php $visible = $page['visibility'][$area] ?? true; ?>
<label><?= $e($label) ?><select name="show_<?= $e($area) ?>">
<option value="1" <?= $visible ? 'selected' : '' ?>>显示</option>
<option value="0" <?= !$visible ? 'selected' : '' ?>>隐藏</option>
</select></label>
<?php endforeach ?>
</fieldset>
<?php
$contentFields = [
'heading' => $page['heading'], 'accent' => $page['accent'], 'lead' => $page['lead'],
+1 -1
View File
@@ -3,7 +3,7 @@ use App\Content\View;
$e = View::escape(...);
?>
<footer class="site-footer" id="contact">
<footer class="site-footer" id="contact"<?= empty($hideFooter) ? '' : ' hidden' ?>>
<div class="wrap">
<div class="footer-grid">
<div class="footer-company" itemscope itemtype="https://schema.org/Organization">
+8 -2
View File
@@ -17,6 +17,8 @@ $footer = SiteDesign::footer($site);
$nav = $header['links'];
$contact = $header['button'];
$theme = $page['theme'] ?? '';
$showHeader = $page['visibility']['header'] ?? true;
$showFooter = $page['visibility']['footer'] ?? true;
?>
<!doctype html>
<html lang="zh-CN" data-type="<?= $e($kind) ?>" data-buttons="solid" data-motion="on">
@@ -53,7 +55,8 @@ $theme = $page['theme'] ?? '';
</head>
<body<?= $kind === 'service' ? ' class="copyright-service"' : '' ?>>
<a class="skip-link" href="#main-content">跳到内容</a>
<header class="masthead">
<?php if ($showHeader || !empty($canvas)): ?>
<header class="masthead"<?= $showHeader ? '' : ' hidden' ?>>
<div class="wrap masthead-inner">
<a class="wordmark" href="/" aria-label="来笙 Laysense 首页">
<?php if ($header['logo'] !== ''): ?>
@@ -77,7 +80,10 @@ $theme = $page['theme'] ?? '';
<?php endif ?>
</div>
</header>
<?php endif ?>
<main id="main-content"<?= $theme !== '' ? ' class="page-theme theme-' . $e($theme) . '"' : '' ?> tabindex="-1"><?= $content ?></main>
<?= View::fragment('footer', ['footer' => $footer]) ?>
<?php if ($showFooter || !empty($canvas)): ?>
<?= View::fragment('footer', ['footer' => $footer, 'hideFooter' => !$showFooter]) ?>
<?php endif ?>
</body>
</html>
+12 -7
View File
@@ -6,12 +6,17 @@ use App\Content\View;
$e = View::escape(...);
$home = $page['slug'] === 'home';
$service = in_array($page['slug'], ['sc', 'shnu-sc'], true);
$showHero = $page['visibility']['hero'] ?? true;
$heroLinks = array_filter($page['sections'], static fn (array $section): bool => $section['style'] === 'hero-links');
$alignments = $page['alignments'];
$alignField = static fn (string $name): string => $canvas ? ' data-studio-align-field="' . $name . '"' : '';
$field = static fn (string $name): string => $canvas ? ' data-studio-field="' . $name . '"' : '';
?>
<?php if (!$showHero && !$canvas): ?><h1 class="sr-only"><?= $e($page['name']) ?></h1><?php endif ?>
<?php if ($showHero || $canvas || $heroLinks): ?>
<section class="hero hero-<?= $e($page['slug']) ?>" id="home" data-enter>
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>">
<?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): ?>
<nav class="breadcrumbs" aria-label="面包屑" itemscope itemtype="https://schema.org/BreadcrumbList">
@@ -56,12 +61,12 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
</div>
<?php endif ?>
</div>
<?php foreach ($page['sections'] as $section): ?>
<?php if ($section['style'] === 'hero-links'): ?>
<?= View::fragment('section', ['section' => $section, 'moment' => false, 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
<?php endif ?>
<?php endif ?>
<?php foreach ($heroLinks as $section): ?>
<?= View::fragment('section', ['section' => $section, 'moment' => false, 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
<?php endforeach ?>
</section>
<?php endif ?>
<?php if ($canvas || $page['quicklinks']): ?>
<nav class="section-nav" aria-label="本页目录"<?= $canvas ? ' data-studio-navigation' : '' ?><?= !$page['quicklinks'] ? ' hidden' : '' ?>>
<div class="wrap section-nav-inner">
@@ -76,8 +81,8 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
<?= View::fragment('section', ['section' => $section, 'moment' => $home && $section['key'] === 'about', 'canvas' => $canvas, 'pageSlug' => $page['slug']]) ?>
<?php endif ?>
<?php endforeach ?>
<?php if ($credit = PageTemplates::photoCredit($page['image'])): ?>
<p class="wrap page-photo-credit">摄影 <a href="<?= $e($credit[2]) ?>"><?= $e($credit[0]) ?></a> ·
<?php if (($showHero || $canvas) && ($credit = PageTemplates::photoCredit($page['image']))): ?>
<p class="wrap page-photo-credit"<?= $showHero ? '' : ' hidden' ?>>摄影 <a href="<?= $e($credit[2]) ?>"><?= $e($credit[0]) ?></a> ·
<?php if ($credit[3]): ?><a href="<?= $e($credit[3]) ?>"><?= $e($credit[1]) ?></a><?php else: ?><?= $e($credit[1]) ?><?php endif ?>
</p>
<?php endif ?>
+14 -10
View File
@@ -40,17 +40,21 @@ $previewRoot = '/assets/page-templates/';
<section data-template-panel="detail" aria-labelledby="page-template-detail-heading" hidden>
<button type="button" class="button button-outline page-template-back" data-template-back="pages">返回套内页面</button>
<h3 id="page-template-detail-heading" data-template-name tabindex="-1"></h3>
<div class="page-template-image"><img data-template-preview width="768" height="480" alt=""></div>
<a class="button button-outline page-template-preview-link" data-template-live target="_blank" rel="noopener">打开完整页面预览</a>
<form class="admin-form" method="post" action="/admin/new-page">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<input type="hidden" name="template">
<div class="form-grid">
<label>页面名称<input name="name" maxlength="100" required></label>
<label>网址标识<input name="slug" maxlength="70" pattern="[a-z0-9]+(-[a-z0-9]+)*" required></label>
<div class="page-template-detail">
<div>
<div class="page-template-image"><img data-template-preview width="768" height="480" alt=""></div>
<a class="button button-outline page-template-preview-link" data-template-live target="_blank" rel="noopener">打开完整页面预览</a>
</div>
<div class="form-submit"><button type="submit" class="button button-primary">用此模板创建草稿</button></div>
</form>
<form class="admin-form" method="post" action="/admin/new-page">
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
<input type="hidden" name="template">
<div class="form-grid">
<label>页面名称<input name="name" maxlength="100" required></label>
<label>网址标识<input name="slug" maxlength="70" pattern="[a-z0-9]+(-[a-z0-9]+)*" required></label>
</div>
<div class="form-submit"><button type="submit" class="button button-primary">用此模板创建草稿</button></div>
</form>
</div>
</section>
</div>
</dialog>