feat(oembed.php): add oembed api and implement in dependent pages

This commit is contained in:
Cory Dransfeldt 2025-05-10 17:19:43 -07:00
parent d95df47274
commit ec03d7ccef
No known key found for this signature in database
15 changed files with 173 additions and 3 deletions

View file

@ -75,6 +75,7 @@
), 250);
$ogImage = htmlspecialchars($artist["image"], ENT_QUOTES, "UTF-8");
$fullUrl = "https://www.coryd.dev" . $requestUri;
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
ob_start();

View file

@ -98,6 +98,7 @@
), 250);
$ogImage = htmlspecialchars($book["image"], ENT_QUOTES, "UTF-8");
$fullUrl = "https://www.coryd.dev" . $requestUri;
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
ob_start();

View file

@ -66,6 +66,7 @@
$pageDescription = truncateText(htmlspecialchars(strip_tags($genre["description"]), ENT_QUOTES, "UTF-8"), 250);
$ogImage = htmlspecialchars($genre["artists"][0]["image"], ENT_QUOTES, "UTF-8");
$fullUrl = "https://www.coryd.dev" . $requestUri;
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
ob_start();

View file

@ -75,6 +75,7 @@
), 250);
$ogImage = htmlspecialchars($movie["backdrop"], ENT_QUOTES, "UTF-8");
$fullUrl = "https://www.coryd.dev" . $requestUri;
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
ob_start();

View file

@ -66,6 +66,7 @@
$pageDescription = truncateText(htmlspecialchars(strip_tags($show["description"]), ENT_QUOTES, "UTF-8"), 250);
$ogImage = htmlspecialchars($show["image"], ENT_QUOTES, "UTF-8");
$fullUrl = "https://www.coryd.dev" . $requestUri;
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
ob_start();

View file

@ -99,6 +99,7 @@ $pagination = [
$pageTitle = "#" . strtolower(ucfirst($tag)) . "";
$pageDescription = "All content tagged with #" . strtolower(ucfirst($tag)) . ".";
$fullUrl = "https://www.coryd.dev" . $requestUri;
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
ob_start();

View file

@ -2,6 +2,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="light dark" />
<meta name="theme-color" content="{{ globals.theme_color }}" />
<meta name="msapplication-TileColor" content="{{ globals.theme_color }}">
<meta name="fediverse:creator" content="{{ globals.mastodon }}" />
<meta name="generator" content="{{ eleventy.generator }}" />
<link href="{{ globals.url }}/og/w50/{% appVersion %}{{ globals.avatar_transparent }}" rel="icon" sizes="any" />

View file

@ -4,6 +4,7 @@
<meta property="og:description" content="<?= cleanMeta($pageDescription ?? '{{ pageDescription | escape }}') ?>" />
<meta property="og:image" content="{{ globals.url }}<?= cleanMeta("/og/w800/{% appVersion %}" . ($ogImage ?? '{{ ogImage }}')) ?>" />
<meta property="og:url" content="<?= cleanMeta($fullUrl ?? '{{ fullUrl }}') ?>" />
<link rel="alternate" type="application/json+oembed" href="<?= cleanMeta($oembedUrl ?? '{{ oembedUrl }}') ?>" title="<?= cleanMeta($pageTitle ?? '{{ pageTitle }}') ?> • {{ globals.site_name }}">
<link rel="canonical" href="<?= cleanMeta($fullUrl ?? '{{ fullUrl }}') ?>" />
<?php if (!empty($pagination)): ?>
<?php if (!empty($pagination['href']['next'])): ?>

View file

@ -1,4 +1,5 @@
{%- assign fullUrl = globals.url | append: page.url -%}
{%- assign oembedUrl = globals.url | append: "/oembed" | append: page.url -%}
{%- capture pageTitle -%}
{%- if page.title -%}
{{ page.title | append: ' • ' | append: globals.site_name }}
@ -74,6 +75,7 @@
{%- if type == 'dynamic' -%}
{% render "metadata/dynamic.php.liquid"
fullUrl:fullUrl,
oembedUrl:oembedUrl,
pageTitle:pageTitle,
pageDescription:pageDescription,
ogImage:ogImage,
@ -82,6 +84,7 @@
{%- else -%}
{% render "metadata/static.liquid"
fullUrl:fullUrl,
oembedUrl:oembedUrl,
pageTitle:pageTitle,
pageDescription:pageDescription,
ogImage:ogImage,

View file

@ -5,5 +5,6 @@
<meta property="og:description" content="{{ description }}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="{{ fullUrl }}" />
<link rel="alternate" type="application/json+oembed" href="{{ oembedUrl }}" title="{{ pageTitle }}">
<link rel="canonical" href="{{ fullUrl }}" />
<meta property="og:image" content="{{ globals.url }}/og/w800/{% appVersion %}{{ globals.avatar }}" />

View file

@ -50,6 +50,9 @@ RewriteRule ^tags/([^/]+)(?:/([0-9]+))?/?$ tags/index.php [L]
## open graph assets
RewriteRule ^og/([a-z0-9\-]+)/([\d\.]+)/([a-f0-9\-]+)\.([a-z0-9]+)$ /api/og-image.php?id=$3&class=$1&v=$2&extension=$4 [L]
## oembed
RewriteRule ^oembed/(.*)$ /api/oembed.php?url=https://www.coryd.dev/$1 [L,QSA]
{% for redirect in redirects -%}
Redirect {{ redirect.status_code | default: "301" }} {{ redirect.source_url }} {{ redirect.destination_url }}
{% endfor -%}