feat: auto-derive youtubeVideoId from URL in reply-context
Build & Deploy / build-and-deploy (push) Successful in 1m50s

Adds a `youtubeId` filter that extracts the video ID from any YouTube
URL (youtube.com?v= and youtu.be/ formats). reply-context.njk now
computes youtubeVideoId automatically from the interaction URL fields,
so YouTube embeds work without needing youtubeVideoId in post frontmatter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
svemagie
2026-04-11 19:35:40 +02:00
parent 24e7a58029
commit 26ab9b82b3
2 changed files with 11 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@
{% set likedUrl = likeOf or like_of %} {% set likedUrl = likeOf or like_of %}
{% set repostedUrl = repostOf or repost_of %} {% set repostedUrl = repostOf or repost_of %}
{% set bookmarkedUrl = bookmarkOf or bookmark_of %} {% set bookmarkedUrl = bookmarkOf or bookmark_of %}
{% set youtubeVideoId = youtubeVideoId or (repostedUrl | youtubeId) or (likedUrl | youtubeId) or (bookmarkedUrl | youtubeId) or (replyTo | youtubeId) %}
{% if replyTo or likedUrl or repostedUrl or bookmarkedUrl %} {% if replyTo or likedUrl or repostedUrl or bookmarkedUrl %}
<aside class="reply-context mb-6" aria-label="Reply context"> <aside class="reply-context mb-6" aria-label="Reply context">
+10
View File
@@ -966,6 +966,16 @@ export default function (eleventyConfig) {
}); });
}); });
eleventyConfig.addFilter("youtubeId", (url) => {
if (!url || typeof url !== "string") return null;
try {
const u = new URL(url);
if (u.hostname === "youtu.be") return u.pathname.slice(1).split("?")[0] || null;
if (u.hostname.endsWith("youtube.com")) return u.searchParams.get("v") || null;
} catch {}
return null;
});
eleventyConfig.addFilter("stripTrailingSlash", (url) => { eleventyConfig.addFilter("stripTrailingSlash", (url) => {
if (!url || typeof url !== "string") return url || ""; if (!url || typeof url !== "string") return url || "";
return url.endsWith("/") ? url.slice(0, -1) : url; return url.endsWith("/") ? url.slice(0, -1) : url;