Add social image URL and metadata to template context
This commit is contained in:
parent
0e63ed1444
commit
611bf75576
3 changed files with 21 additions and 11 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue