[READ-ONLY] Mirror of https://github.com/flo-bit/dogumentation. Simple, minimalistic documentation template using astro flo-bit.dev/dogumentation/
0

Configure Feed

Select the types of activity you want to include in your feed.

dogumentation / src / embeds / youtube / matcher.ts
634 B 14 lines
1// Thanks to eleventy-plugin-youtube-embed 2// https://github.com/gfscott/eleventy-plugin-youtube-embed/blob/main/lib/extractMatches.js 3const urlPattern = 4 /(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:\/\/)??(?:w{3}\.)??(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/|shorts\/)??([A-Za-z0-9-_]{11})(?:[^\s<>]*)(?=(\s*))\4(?:<\/a>)??(?=(\s*))\5/; 5 6/** 7 * Extract a YouTube ID from a URL if it matches the pattern. 8 * @param url URL to test 9 * @returns A YouTube video ID or undefined if none matched 10 */ 11export default function matcher(url: string): string | undefined { 12 const match = url.match(urlPattern); 13 return match?.[3]; 14}