Edit shared headers and footers as page types

This commit is contained in:
2026-11-23 20:58:42 +08:00
parent 636788b65c
commit 9d386dd39c
40 changed files with 725 additions and 937 deletions
+13 -21
View File
@@ -5,40 +5,32 @@ use App\Content\View;
$e = View::escape(...);
$data = $header['payload'];
$brand = $data['brand'] ?: $site['name'];
$layoutEditor ??= false;
$part = static fn (string $component): string => $layoutEditor ? ' data-layout-component="' . $component . '"' : '';
$layoutTemplate ??= false;
?>
<header class="masthead masthead-<?= $e($header['preset']) ?>"<?= $showHeader ? '' : ' hidden' ?>>
<div class="wrap masthead-inner">
<?php foreach ($data['components'] as $component): ?>
<?php if ($component === 'brand'): ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页"<?= $part('brand') ?>>
<?php if ($layoutEditor): ?><img alt="" hidden><span data-layout-text="brand"></span>
<?php elseif ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页">
<?php if ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
</a>
<?php elseif ($component === 'links' && ($layoutEditor || $data['links'])): ?>
<?php if (!$layoutEditor): ?>
<?php elseif ($component === 'links' && $data['links']): ?>
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
<span></span><span></span><span class="sr-only">菜单</span>
</button>
<?php endif ?>
<nav id="primary-navigation" class="primary-nav" aria-label="主导航"<?= $part('links') ?>>
<nav id="primary-navigation" class="primary-nav" aria-label="主导航">
<?php foreach ($data['links'] as [$url, $label]): ?>
<a href="<?= $e($url) ?>"<?= $url === $path ? ' aria-current="page"' : '' ?>><?= $e($label) ?></a>
<?php endforeach ?>
</nav>
<?php elseif ($component === 'action' && ($layoutEditor || $data['action'])): ?>
<?php [$url, $label, $style, $blank] = $data['action'][0] ?? ['/', '', 'outline', false]; ?>
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?><?= $part('action') ?><?= $layoutEditor ? ' data-layout-text="action_label"' : '' ?>><?= $e($label) ?></a>
<?php elseif ($component === 'account' && ($layoutEditor || $member)): ?>
<?php if ($visitor): ?>
<a class="site-account" href="/account" aria-label="打开用户中心">
<?php if ($visitor['avatar'] !== ''): ?><img class="account-avatar" src="<?= $e($visitor['avatar']) ?>" alt="" width="36" height="36"><?php else: ?>
<span class="account-avatar account-initial" aria-hidden="true"><?= $e(mb_substr($visitor['name'], 0, 1)) ?></span>
<?php endif ?>
</a>
<?php else: ?>
<a class="button button-outline site-account" href="/account/login/<?= $e($header['id']) ?>"<?= $part('account') ?>>登录</a>
<?php elseif ($component === 'action' && $data['action']): ?>
<?php [$url, $label, $style, $blank] = $data['action'][0]; ?>
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?>><?= $e($label) ?></a>
<?php elseif ($component === 'account'): ?>
<?php if ($layoutTemplate && $header['preset'] === 'member'): ?>
<a class="button button-outline site-account studio-member-slot" href="/account">登录</a>
<?php elseif ($member): ?>
<?= View::fragment('member-account', ['layoutId' => $header['id'], 'visitor' => $visitor]) ?>
<?php endif ?>
<?php endif ?>
<?php endforeach ?>