fix(oembed.php): remove fallback hardcoded values; correct case where description might be empty

This commit is contained in:
Cory Dransfeldt 2025-05-25 13:09:54 -07:00
parent 36fbba761a
commit 929bc9f9f8
No known key found for this signature in database
3 changed files with 12 additions and 16 deletions

View file

@ -16,11 +16,12 @@ class OembedHandler extends BaseHandler
$relativePath = $parsed['path'] ?? null; $relativePath = $parsed['path'] ?? null;
if (!$requestUrl || $relativePath === '/') $this->sendResponse($this->buildResponse( if (!$requestUrl || $relativePath === '/') $this->sendResponse($this->buildResponse(
$globals['site_name'], $globals['site_name'],
$globals['url'], $globals['url'],
$globals['metadata']['open_graph_image'], $globals['metadata']['open_graph_image'],
$globals $globals,
)); $globals['site_description']
));
if (!$relativePath) $this->sendErrorResponse('Invalid url', 400); if (!$relativePath) $this->sendErrorResponse('Invalid url', 400);
@ -89,8 +90,8 @@ class OembedHandler extends BaseHandler
'provider_name' => $globals['site_name'], 'provider_name' => $globals['site_name'],
'provider_url' => $globals['url'], 'provider_url' => $globals['url'],
'thumbnail_url' => $globals['url'] . '/og/w800' . $imagePath, 'thumbnail_url' => $globals['url'] . '/og/w800' . $imagePath,
'html' => $html, 'html' => $html ?? $globals['site_description'],
'description' => $safeDescription, 'description' => $safeDescription ?? $globals['site_description'],
]; ];
} }
@ -100,12 +101,7 @@ class OembedHandler extends BaseHandler
if ($this->cache && $this->cache->exists($cacheKey)) return json_decode($this->cache->get($cacheKey), true); if ($this->cache && $this->cache->exists($cacheKey)) return json_decode($this->cache->get($cacheKey), true);
$globals = $this->fetchFromApi('optimized_globals', 'limit=1')[0] ?? [ $globals = $this->fetchFromApi('optimized_globals', 'limit=1')[0];
'author' => 'Cory Dransfeldt',
'site_name' => 'coryd.dev',
'url' => 'https://www.coryd.dev',
'avatar' => ''
];
if ($this->cache) $this->cache->setex($cacheKey, 3600, json_encode($globals)); if ($this->cache) $this->cache->setex($cacheKey, 3600, json_encode($globals));

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "7.0.7", "version": "7.0.8",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "7.0.7", "version": "7.0.8",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"minisearch": "^7.1.2", "minisearch": "^7.1.2",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "7.0.7", "version": "7.0.8",
"description": "The source for my personal site. Built using 11ty (and other tools).", "description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module", "type": "module",
"engines": { "engines": {