feat(*): refactor metadata handling; move metadata to backend where possible, refine client views
This commit is contained in:
parent
929bc9f9f8
commit
9687509e4a
35 changed files with 506 additions and 339 deletions
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
require_once "icons.php";
|
||||
require_once "media.php";
|
||||
require_once "metadata.php";
|
||||
require_once "paginator.php";
|
||||
require_once "routing.php";
|
||||
require_once "strings.php";
|
||||
|
|
33
server/utils/metadata.php
Normal file
33
server/utils/metadata.php
Normal 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');
|
||||
}
|
||||
|
||||
?>
|
|
@ -68,11 +68,4 @@
|
|||
return $string . 's' . ($trailing ? $trailing : '');
|
||||
}
|
||||
|
||||
function cleanMeta($value) {
|
||||
$value = trim($value ?? '');
|
||||
$value = str_replace(["\r", "\n"], ' ', $value);
|
||||
$value = preg_replace('/\s+/', ' ', $value);
|
||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue