Add social image URL and metadata to template context

This commit is contained in:
Ruben 2026-03-17 11:23:07 +01:00
parent 0e63ed1444
commit 611bf75576
3 changed files with 21 additions and 11 deletions

View file

@ -249,6 +249,14 @@ switch ($parsedPath['type']) {
? $langPrefix . '/' . trim($ctx->requestPath, '/') . '/feed.xml'
: null;
// Build social image URL from cover image if present
$coverImage = findCoverImage($dir);
$socialImageUrl = null;
if ($coverImage) {
$relativePath = trim(str_replace($ctx->contentDir, '', $dir), '/');
$socialImageUrl = '/' . ($relativePath ? $relativePath . '/' : '') . $coverImage;
}
// Store for base template (renderTemplate reads these from context)
$ctx->set('pageTitle', $pageTitle);
$ctx->set('metaDescription', $metaDescription);
@ -257,6 +265,7 @@ switch ($parsedPath['type']) {
$ctx->set('pageJsUrl', $pageJsUrl);
$ctx->set('pageJsHash', $pageJsHash);
$ctx->set('feedUrl', $feedUrl);
$ctx->set('socialImageUrl', $socialImageUrl);
// Let plugins add template variables
$templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [
@ -270,7 +279,9 @@ switch ($parsedPath['type']) {
'pageJsHash' => $pageJsHash,
'items' => $items,
'pageContent' => $pageContent,
'feedUrl' => $feedUrl
'feedUrl' => $feedUrl,
'socialImageUrl' => $socialImageUrl,
'metadata' => $metadata
], $ctx);
extract($templateVars);