chore(oembed.php): add additional html/description to oembed respobse

This commit is contained in:
Cory Dransfeldt 2025-05-12 14:29:32 -07:00
parent 84a1c0d4cc
commit c29105f42d
No known key found for this signature in database
3 changed files with 19 additions and 12 deletions

View file

@ -1,5 +1,6 @@
<?php <?php
require __DIR__ . '/../server/utils/init.php';
require __DIR__ . "/Classes/BaseHandler.php"; require __DIR__ . "/Classes/BaseHandler.php";
use App\Classes\BaseHandler; use App\Classes\BaseHandler;
@ -31,7 +32,8 @@ class OembedHandler extends BaseHandler
$item['title'], $item['title'],
$item['url'], $item['url'],
$item['image_url'], $item['image_url'],
$globals $globals,
$item['description'] ?? ''
)); ));
} }
@ -49,8 +51,12 @@ class OembedHandler extends BaseHandler
$this->sendErrorResponse('No match found', 404); $this->sendErrorResponse('No match found', 404);
} }
private function buildResponse(string $title, string $url, string $imagePath, array $globals): array private function buildResponse(string $title, string $url, string $imagePath, array $globals, string $description = ''): array
{ {
$safeDescription = truncateText(strip_tags(parseMarkdown($description)), 175);
$html = '<p><a href="' . htmlspecialchars($url) . '">' . htmlspecialchars($title) . '</a></p>';
if ($description) $html .= '<p>' . htmlspecialchars($safeDescription, ENT_QUOTES, 'UTF-8') . '</p>';
return [ return [
'version' => '1.0', 'version' => '1.0',
'type' => 'link', 'type' => 'link',
@ -59,7 +65,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' => '<a href="' . htmlspecialchars($url) . '">' . htmlspecialchars($title) . '</a>', 'html' => $html,
'description' => $safeDescription,
]; ];
} }

16
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "4.0.4", "version": "4.0.5",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "4.0.4", "version": "4.0.5",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"html-minifier-terser": "7.2.0", "html-minifier-terser": "7.2.0",
@ -1890,9 +1890,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.5.151", "version": "1.5.152",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.151.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.152.tgz",
"integrity": "sha512-Rl6uugut2l9sLojjS4H4SAr3A4IgACMLgpuEMPYCVcKydzfyPrn5absNRju38IhQOf/NwjJY8OGWjlteqYeBCA==", "integrity": "sha512-xBOfg/EBaIlVsHipHl2VdTPJRSvErNUaqW8ejTq5OlOlIYx1wOllCHsAvAIrr55jD1IYEfdR86miUEt8H5IeJg==",
"dev": true, "dev": true,
"license": "ISC" "license": "ISC"
}, },
@ -4263,9 +4263,9 @@
} }
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "7.7.1", "version": "7.7.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz",
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC",
"bin": { "bin": {

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "4.0.4", "version": "4.0.5",
"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": {