Speichere Name, Sprungmarke und Ausblenden je Abschnitt und gib sie auf der Website aus
Name nur zur Orientierung, Sprungmarke als Element-Kennung (je Seite eindeutig, reservierte Kennungen gesperrt), ausgeblendete Abschnitte erscheinen nie öffentlich und zählen weder für die Hauptüberschrift noch für Trenner. SafeUrl nimmt #marke an. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
00b7ce9b3f
commit
3a37e8a7a1
5 files changed
+391
-14
No files matched your search
@@ -17,6 +17,9 @@
|
||||
* - Ein Abschnitt ohne darstellbares Widget entfällt samt Hintergrund und Trenner.
|
||||
* - Das erste dargestellte Widget der Seite ist der Seiteneinstieg (Überschrift erster Ordnung).
|
||||
* - Trenner stehen zwischen Abschnitten, nie nach dem letzten.
|
||||
* - Ein ausgeblendeter Abschnitt („hidden“) erscheint nie auf der Website und zählt weder für das erste Widget noch für
|
||||
* Trenner. Nur die Vorschau zeigt an seiner Stelle einen schmalen Hinweis (ohne Inhalt).
|
||||
* - Eine Sprungmarke („anchor“) ist die Element-Kennung des Abschnitts; ohne Sprungmarke gilt „bereich-<Kennung>“.
|
||||
*/
|
||||
class SectionRenderer
|
||||
{
|
||||
@@ -31,6 +34,14 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
||||
$first = true;
|
||||
|
||||
foreach ($sections as $section) {
|
||||
if ($section['hidden'] ?? false) {
|
||||
if ($context->preview) {
|
||||
$rendered[] = ['note' => $this->hiddenNote($section)];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$cells = [];
|
||||
$shown = false;
|
||||
$units = SectionLayouts::units($section['layout']);
|
||||
@@ -54,13 +65,28 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$last = count($rendered) - 1;
|
||||
$last = -1;
|
||||
|
||||
foreach ($rendered as $position => $item) {
|
||||
if (isset($item['section'])) {
|
||||
$last = $position;
|
||||
}
|
||||
}
|
||||
|
||||
$index = 0;
|
||||
|
||||
foreach ($rendered as $position => $item) {
|
||||
if (! isset($item['section'])) {
|
||||
$html .= $item['note'];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($rendered as $index => $item) {
|
||||
$html .= $this->renderSection($item['section'], $item['cells'], $index, $context);
|
||||
$index++;
|
||||
|
||||
$divider = $item['section']['style']['divider'] ?? 'none';
|
||||
if ($index < $last && in_array($divider, ['line', 'accent'], true)) {
|
||||
if ($position < $last && in_array($divider, ['line', 'accent'], true)) {
|
||||
$html .= '<div class="section-divider section-divider-'.$divider.'" aria-hidden="true"><span></span></div>';
|
||||
}
|
||||
}
|
||||
@@ -68,6 +94,18 @@ public function renderAll(array $sections, RenderContext $context): HtmlString
|
||||
return new HtmlString($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hinweis der Vorschau an der Stelle eines ausgeblendeten Abschnitts.
|
||||
*
|
||||
* @param array<string, mixed> $section
|
||||
*/
|
||||
private function hiddenNote(array $section): string
|
||||
{
|
||||
$name = is_string($section['name'] ?? null) && $section['name'] !== '' ? '„'.$section['name'].'“ ' : '';
|
||||
|
||||
return '<div class="section-hidden-note" role="note">Abschnitt '.e($name).'ist für die Website ausgeblendet und erscheint hier nur als Hinweis.</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $section
|
||||
* @param list<array{units: int, html: string}> $cells alle Plätze des Rasters in ihrer Reihenfolge; html '' = leer
|
||||
@@ -106,7 +144,11 @@ private function renderSection(array $section, array $cells, int $index, RenderC
|
||||
$classes[] = $scope;
|
||||
}
|
||||
|
||||
$id = is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '';
|
||||
// Die Sprungmarke ist die Kennung, die ein Link „#marke“ anspringt; ohne sie bleibt die bisherige Kennung.
|
||||
$anchor = PageSections::cleanAnchor($section['anchor'] ?? null);
|
||||
$id = $anchor !== null
|
||||
? ' id="'.e($anchor).'"'
|
||||
: (is_string($section['id'] ?? null) ? ' id="bereich-'.e($section['id']).'"' : '');
|
||||
$html = '<div class="'.e(implode(' ', $classes)).'"'.$id.'>';
|
||||
|
||||
if ($hasImage) {
|
||||
|
||||
Reference in new issue
Block a user