feat(*): refactor metadata handling; move metadata to backend where possible, refine client views

This commit is contained in:
Cory Dransfeldt 2025-05-25 20:15:45 -07:00
parent 929bc9f9f8
commit 9687509e4a
No known key found for this signature in database
35 changed files with 506 additions and 339 deletions

33
server/utils/metadata.php Normal file
View file

@ -0,0 +1,33 @@
<?php
function setupPageMetadata(array $page, string $requestUri): array {
$globals = $page['globals'] ?? [];
$title = htmlspecialchars($page["metadata"]["title"] ?? "", ENT_QUOTES, "UTF-8");
$description = htmlspecialchars($page["metadata"]["description"] ?? "", ENT_QUOTES, "UTF-8");
$image = htmlspecialchars(
$page["metadata"]["open_graph_image"] ?? $globals["metadata"]["open_graph_image"] ?? "",
ENT_QUOTES,
"UTF-8"
);
$fullUrl = $globals["url"] . $requestUri;
$oembedUrl = $globals["url"] . "/oembed" . $requestUri;
return [
'pageTitle' => $title,
'pageDescription' => $description,
'ogImage' => $image,
'fullUrl' => $fullUrl,
'oembedUrl' => $oembedUrl,
'globals' => $globals
];
}
function cleanMeta($value) {
$value = trim($value ?? '');
$value = str_replace(["\r", "\n"], ' ', $value);
$value = preg_replace('/\s+/', ' ', $value);
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
?>