Refine homepage shortcode layout and rendering cleanup

This commit is contained in:
AudioCore Bot
2026-03-05 20:15:48 +00:00
parent 8d12c68c0c
commit 4f50b611b0
5 changed files with 155 additions and 48 deletions

View File

@@ -39,12 +39,22 @@ class PagesController
return $this->notFound();
}
$rendered = Shortcodes::render((string)$page['content_html'], [
'page_slug' => $slug,
'page_title' => (string)$page['title'],
]);
// WYSIWYG editors often wrap shortcode blocks in <p>, which breaks grid placement.
$rendered = preg_replace(
'~<p>\s*(<(?:section|div|form|a)[^>]*class="[^"]*ac-shortcode[^"]*"[^>]*>.*?</(?:section|div|form|a)>)\s*</p>~is',
'$1',
$rendered
) ?? $rendered;
$rendered = preg_replace('~(<(?:section|div|form|a)[^>]*class="[^"]*ac-shortcode[^"]*"[^>]*>)\s*<br\s*/?>~i', '$1', $rendered) ?? $rendered;
$rendered = preg_replace('~<br\s*/?>\s*(</(?:section|div|form|a)>)~i', '$1', $rendered) ?? $rendered;
return new Response($this->view->render('site/show.php', [
'title' => (string)$page['title'],
'content_html' => Shortcodes::render((string)$page['content_html'], [
'page_slug' => $slug,
'page_title' => (string)$page['title'],
]),
'content_html' => $rendered,
]));
}

View File

@@ -33,6 +33,26 @@ Shortcodes::register('hero', static function (array $attrs = []): string {
return $html;
});
Shortcodes::register('home-catalog', static function (array $attrs = []): string {
$releaseLimit = max(1, min(12, (int)($attrs['release_limit'] ?? 8)));
$artistLimit = max(1, min(10, (int)($attrs['artist_limit'] ?? 6)));
$chartLimit = max(1, min(20, (int)($attrs['chart_limit'] ?? 10)));
$hero = Shortcodes::render('[hero eyebrow="Catalog Focus" title="Latest Drops" subtitle="Fresh releases, artists, and best sellers." cta_text="Browse Releases" cta_url="/releases" secondary_text="Meet Artists" secondary_url="/artists"]');
$releases = Shortcodes::render('[latest-releases limit="' . $releaseLimit . '"]');
$artists = Shortcodes::render('[new-artists limit="' . $artistLimit . '"]');
$chart = Shortcodes::render('[sale-chart type="tracks" window="latest" limit="' . $chartLimit . '"]');
$newsletter = Shortcodes::render('[newsletter-signup title="Join the list" button="Subscribe"]');
return '<section class="ac-home-catalog">'
. $hero
. '<div class="ac-home-columns">'
. '<div class="ac-home-main">' . $releases . $chart . '</div>'
. '<aside class="ac-home-side">' . $artists . $newsletter . '</aside>'
. '</div>'
. '</section>';
});
return function (Router $router): void {
$controller = new PagesController();
$router->get('/page', [$controller, 'show']);

View File

@@ -4,7 +4,7 @@ $contentHtml = $content_html ?? '';
ob_start();
?>
<section class="card">
<div class="page-content" style="margin-top:14px; color:var(--muted); line-height:1.8;">
<div class="page-content" style="margin-top:14px; color:var(--muted);">
<?= $contentHtml ?>
</div>
</section>