forked from laysense/laysite
101 lines
7.5 KiB
PHP
101 lines
7.5 KiB
PHP
<?php
|
|
use App\Content\Buttons;
|
|
use App\Content\CanvasStyle;
|
|
use App\Content\SiteDesign;
|
|
use App\Content\View;
|
|
|
|
$e = View::escape(...);
|
|
$home = $page['slug'] === 'home';
|
|
$shared = !empty($page['layout_kind']);
|
|
$system = ($page['page_type'] ?? 'page') !== 'page';
|
|
$showHero = $page['visibility']['hero'] ?? true;
|
|
$heroLinks = array_filter($page['sections'], static fn (array $section): bool => $section['style'] === 'hero-links');
|
|
$alignments = $page['alignments'];
|
|
$presentation = $page['presentation'] ?? [];
|
|
$showBreadcrumbs = !$home && !$shared && !$system;
|
|
$customCrumbs = array_key_exists('breadcrumbLinks', $presentation);
|
|
$crumbs = !$showBreadcrumbs ? [] : ($customCrumbs
|
|
? SiteDesign::parseLinks($presentation['breadcrumbLinks']) : [['/', '首页'], ['/' . $page['slug'], $page['name']]]);
|
|
$customHero = array_key_exists('heroHtml', $presentation);
|
|
$renderManagedHero = !$customHero || $canvas;
|
|
$style = static fn (string $role): string => CanvasStyle::classes($presentation, $role);
|
|
$text = static fn (string $role, string $value): string => CanvasStyle::text($presentation, $role, $value);
|
|
$styleField = static fn (string $role): string => $canvas ? ' data-studio-style-field="' . $role . '"' : '';
|
|
$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 && !$shared): ?><h1 class="sr-only"><?= $e($page['name']) ?></h1><?php endif ?>
|
|
<?php if ($showHero || $canvas || $heroLinks): ?>
|
|
<section class="hero hero-<?= $e($page['slug']) ?><?= $style('hero') ?>" id="home" data-enter<?= $canvas ? ' data-studio-hero' : '' ?><?= $styleField('hero') ?>>
|
|
<?php if ($showHero || $canvas): ?>
|
|
<?php if ($customHero || $canvas): ?>
|
|
<div class="studio-hero-html rich"<?= $canvas ? ' data-studio-hero-source data-studio-part="body"' : '' ?><?= !$customHero || !$showHero ? ' hidden' : '' ?>><?= $presentation['heroHtml'] ?? '' ?></div>
|
|
<?php endif ?>
|
|
<?php if ($renderManagedHero): ?>
|
|
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>"<?= $canvas ? ' data-studio-hero-content' : '' ?><?= $showHero && !$customHero ? '' : ' hidden' ?>>
|
|
<div class="hero-copy">
|
|
<?php if ($showBreadcrumbs && ($crumbs || $canvas)): ?>
|
|
<nav class="breadcrumbs<?= $style('breadcrumbs') ?>" aria-label="面包屑" itemscope itemtype="https://schema.org/BreadcrumbList"<?= $canvas ? ' data-studio-breadcrumbs' : '' ?><?= $styleField('breadcrumbs') ?><?= $crumbs ? '' : ' hidden' ?>>
|
|
<?php foreach ($crumbs as $index => [$url, $label]): ?>
|
|
<?php $role = 'crumb-' . $index; ?>
|
|
<?php if ($index > 0): ?><span class="crumb-divider" aria-hidden="true">/</span><?php endif ?>
|
|
<span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
|
|
<a itemprop="item" href="<?= $e($url) ?>"<?= $index === count($crumbs) - 1 ? ' aria-current="page"' : '' ?><?= $styleField($role) ?> class="<?= trim($style($role)) ?>"><span itemprop="name"><?= $text($role, $label) ?></span></a>
|
|
<meta itemprop="position" content="<?= $index + 1 ?>">
|
|
</span>
|
|
<?php endforeach ?>
|
|
</nav>
|
|
<?php elseif (!$showBreadcrumbs): ?>
|
|
<p class="overline hero-label"<?= $field('eyebrow') ?><?= $styleField('eyebrow') ?>><?= $text('eyebrow', $presentation['heroEyebrow'] ?? $site['name']) ?></p>
|
|
<?php endif ?>
|
|
<h1<?= isset($alignments['heading']) ? ' class="' . trim(View::alignmentClass($alignments['heading'])) . '"' : '' ?><?= $alignField('heading') ?>><span class="hero-heading-primary<?= $style('heading') ?>"<?= $field('heading') ?><?= $styleField('heading') ?>><?= $text('heading', $page['heading']) ?></span><?php if ($canvas || $page['accent'] !== ''): ?><span class="hero-accent<?= $style('accent') ?>"<?= $field('accent') ?><?= $styleField('accent') ?>><?= $text('accent', $page['accent']) ?></span><?php endif ?></h1>
|
|
<p class="hero-lead<?= View::alignmentClass($alignments['lead'] ?? null) ?><?= $style('lead') ?>"<?= $field('lead') ?><?= $alignField('lead') ?><?= $styleField('lead') ?>><?= $text('lead', $page['lead']) ?></p>
|
|
<div class="actions hero-actions<?= View::alignmentClass($alignments['actions'] ?? null) ?><?= $style('actions') ?>"<?= $alignField('actions') ?><?= $styleField('actions') ?>>
|
|
<?php foreach (Buttons::validate($page['actions']) as $index => [$url, $label, $buttonStyle, $blank]): ?>
|
|
<?php $role = 'action-' . $index; ?>
|
|
<a class="<?= $e(Buttons::css($buttonStyle)) ?><?= $style($role) ?>" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?><?= $canvas ? ' data-studio-action="' . $index . '"' : '' ?><?= $styleField($role) ?>><?= $text($role, $label) ?></a>
|
|
<?php endforeach ?>
|
|
</div>
|
|
</div>
|
|
<?php if ($canvas || $page['image'] !== ''): ?>
|
|
<div class="hero-visual app-frame<?= $page['image_scale'] ? ' studio-media-' . $e($page['image_scale']) : '' ?><?= View::alignmentClass($alignments['image'] ?? null) ?><?= $style('image') ?>" data-visual<?= $alignField('image') ?><?= $styleField('image') ?><?= $page['image'] === '' ? ' hidden' : '' ?>>
|
|
<img<?= $page['image'] === '' ? '' : ' src="' . $e($page['image']) . '"' ?> alt="<?= $e($page['alt']) ?>" width="1448" height="1086" fetchpriority="high"<?= $canvas ? ' data-studio-hero-image' : '' ?>>
|
|
</div>
|
|
<?php endif ?>
|
|
</div>
|
|
<?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<?= $style('navigation') ?>" aria-label="本页目录"<?= $canvas ? ' data-studio-navigation' : '' ?><?= $styleField('navigation') ?><?= !$page['quicklinks'] ? ' hidden' : '' ?>>
|
|
<div class="wrap section-nav-inner">
|
|
<?php foreach ($page['quicklinks'] as $index => [$url, $label]): ?>
|
|
<?php $role = 'nav-' . $index; ?>
|
|
<a class="<?= trim($style($role)) ?>" href="<?= $e($url) ?>"<?= $styleField($role) ?>><?= $text($role, $label) ?></a>
|
|
<?php endforeach ?>
|
|
</div>
|
|
</nav>
|
|
<?php endif ?>
|
|
<?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 endforeach ?>
|
|
<?php if ($canvas): ?>
|
|
<?php if ($shared): ?>
|
|
<p class="wrap studio-layout-empty" data-studio-empty-layout hidden>从「组件」添加版式,或在页面设置中显示首屏。</p>
|
|
<?php endif ?>
|
|
<template data-studio-section-end><?= View::fragment('section', [
|
|
'section' => ['style' => 'plain', 'key' => 'new', 'version' => null, 'title' => '', 'lead' => '', 'body' => ''],
|
|
'moment' => false, 'canvas' => true,
|
|
]) ?></template>
|
|
<template data-studio-section-layout><?= View::fragment('section', [
|
|
'section' => ['style' => 'layout', 'key' => 'new-layout', 'version' => null, 'title' => '', 'lead' => '', 'body' => ''],
|
|
'moment' => false, 'canvas' => true,
|
|
]) ?></template>
|
|
<?php endif ?>
|