47 lines
3.0 KiB
PHP
47 lines
3.0 KiB
PHP
<?php
|
|
use App\Content\Buttons;
|
|
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 . '"' : '';
|
|
?>
|
|
<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>
|
|
<?php elseif ($component === 'links' && ($layoutEditor || $data['links'])): ?>
|
|
<?php if (!$layoutEditor): ?>
|
|
<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') ?>>
|
|
<?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 endif ?>
|
|
<?php endif ?>
|
|
<?php endforeach ?>
|
|
</div>
|
|
</header>
|