feat: auto-derive youtubeVideoId from URL in reply-context
Build & Deploy / build-and-deploy (push) Successful in 1m50s
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:
@@ -8,6 +8,7 @@
|
||||
{% set likedUrl = likeOf or like_of %}
|
||||
{% set repostedUrl = repostOf or repost_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 %}
|
||||
<aside class="reply-context mb-6" aria-label="Reply context">
|
||||
|
||||
@@ -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) => {
|
||||
if (!url || typeof url !== "string") return url || "";
|
||||
return url.endsWith("/") ? url.slice(0, -1) : url;
|
||||
|
||||
Reference in New Issue
Block a user