Add Open Graph tags functionality

This commit is contained in:
Ruben 2025-11-04 23:00:53 +01:00
parent 6879fad5fb
commit 875408a27c
2 changed files with 27 additions and 0 deletions

View file

@ -64,6 +64,15 @@ function renderFile(Context $ctx, string $filePath): void {
$pageCssUrl = $pageCss['url'] ?? null; $pageCssUrl = $pageCss['url'] ?? null;
$pageCssHash = $pageCss['hash'] ?? null; $pageCssHash = $pageCss['hash'] ?? null;
// Check for cover image for social media
$coverImage = findCoverImage($pageDir);
$socialImageUrl = null;
if ($coverImage) {
$relativePath = str_replace($ctx->contentDir, '', $pageDir);
$relativePath = trim($relativePath, '/');
$socialImageUrl = '/' . ($relativePath ? $relativePath . '/' : '') . $coverImage;
}
// Wrap content with page template // Wrap content with page template
ob_start(); ob_start();
include $ctx->templates->page; include $ctx->templates->page;
@ -107,6 +116,15 @@ function renderMultipleFiles(Context $ctx, array $filePaths, string $pageDir): v
$pageCssUrl = $pageCss['url'] ?? null; $pageCssUrl = $pageCss['url'] ?? null;
$pageCssHash = $pageCss['hash'] ?? null; $pageCssHash = $pageCss['hash'] ?? null;
// Check for cover image for social media
$coverImage = findCoverImage($pageDir);
$socialImageUrl = null;
if ($coverImage) {
$relativePath = str_replace($ctx->contentDir, '', $pageDir);
$relativePath = trim($relativePath, '/');
$socialImageUrl = '/' . ($relativePath ? $relativePath . '/' : '') . $coverImage;
}
// Wrap content with page template // Wrap content with page template
ob_start(); ob_start();
include $ctx->templates->page; include $ctx->templates->page;

View file

@ -142,6 +142,15 @@ switch ($parsedPath['type']) {
$pageCssUrl = $pageCss['url'] ?? null; $pageCssUrl = $pageCss['url'] ?? null;
$pageCssHash = $pageCss['hash'] ?? null; $pageCssHash = $pageCss['hash'] ?? null;
// Check for cover image for social media
$coverImage = findCoverImage($dir);
$socialImageUrl = null;
if ($coverImage) {
$relativePath = str_replace($ctx->contentDir, '', $dir);
$relativePath = trim($relativePath, '/');
$socialImageUrl = '/' . ($relativePath ? $relativePath . '/' : '') . $coverImage;
}
include $ctx->templates->base; include $ctx->templates->base;
exit; exit;