From a4a9af904c21caa52f948e8844c8177ff84efb35 Mon Sep 17 00:00:00 2001 From: nemanjam Date: Wed, 10 Jul 2024 19:23:01 +0200 Subject: [PATCH] add astro-embed and handle Youtube expand --- package.json | 1 + src/components/Share.astro | 4 +- src/components/YouTube.astro | 58 ++++++++++----- src/components/YouTube.old.astro | 28 ++++++++ src/pages/design/embeds.mdx | 48 ++++++++++++- src/pages/design/images.mdx | 25 ------- src/pages/design/youtube-old.mdx | 34 +++++++++ src/types/utils.ts | 5 +- yarn.lock | 120 +++++++++++++++++++++++++++++++ 9 files changed, 274 insertions(+), 49 deletions(-) create mode 100644 src/components/YouTube.old.astro create mode 100644 src/pages/design/youtube-old.mdx diff --git a/package.json b/package.json index f4411f2..4d2d98e 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@fontsource-variable/inter": "^5.0.18", "@tailwindcss/typography": "^0.5.13", "astro": "^4.11.3", + "astro-embed": "^0.7.2", "astro-expressive-code": "^0.35.3", "astro-icon": "^1.1.0", "astro-og-canvas": "^0.5.1", diff --git a/src/components/Share.astro b/src/components/Share.astro index 1812a50..470fc32 100644 --- a/src/components/Share.astro +++ b/src/components/Share.astro @@ -13,7 +13,7 @@ import { cva } from 'class-variance-authority'; import { DEFAULT_METADATA } from '@/constants/metadata'; import { CONFIG } from '@/config'; -import type { InferProps } from '@/types/utils'; +import type { ComponentProps } from 'astro/types'; import type { VariantProps } from 'class-variance-authority'; const shareVariants = cva('', { @@ -22,7 +22,7 @@ const shareVariants = cva('', { }, }); -type SocialShareProps = Omit, 'buttons'>; +type SocialShareProps = Omit, 'buttons'>; export interface Props extends SocialShareProps, VariantProps { class?: string; } diff --git a/src/components/YouTube.astro b/src/components/YouTube.astro index 7c8844f..c3a693b 100644 --- a/src/components/YouTube.astro +++ b/src/components/YouTube.astro @@ -1,28 +1,48 @@ --- -import { cn } from '@/utils/styles'; +import { YouTube as YouTubeAstroEmbed } from 'astro-embed'; -export type Props = { - title: string; - code: string; - wide?: boolean; -}; +import { cva } from 'class-variance-authority'; -// add cva +import type { ComponentProps } from 'astro/types'; +import type { VariantProps } from 'class-variance-authority'; -const { title, code, wide } = Astro.props; +type YouTubeAstroEmbedProps = ComponentProps; -const src = `https://www.youtube-nocookie.com/embed/${code}?autoplay=1&rel=0`; +const youtubeVariants = cva('', { + variants: { + size: { sm: 'max-w-3xl', full: '', 'expand-sm': 'expand-sm', 'expand-lg': 'expand-lg' }, + }, +}); -const playButtonSvg = ``; +export interface Props extends YouTubeAstroEmbedProps, VariantProps { + class?: string; +} -const srcdoc = `${title}
${title}
${playButtonSvg}
`; +const { size = 'sm', class: className, ...props } = Astro.props; + +let posterQuality: YouTubeAstroEmbedProps['posterQuality'] = undefined; + +switch (size) { + case 'full': + posterQuality = 'high'; + break; + case 'expand-sm': + case 'expand-lg': + posterQuality = 'max'; + break; + + default: + posterQuality = 'default'; + break; +} --- - +
+ +
+ + diff --git a/src/components/YouTube.old.astro b/src/components/YouTube.old.astro new file mode 100644 index 0000000..7c8844f --- /dev/null +++ b/src/components/YouTube.old.astro @@ -0,0 +1,28 @@ +--- +import { cn } from '@/utils/styles'; + +export type Props = { + title: string; + code: string; + wide?: boolean; +}; + +// add cva + +const { title, code, wide } = Astro.props; + +const src = `https://www.youtube-nocookie.com/embed/${code}?autoplay=1&rel=0`; + +const playButtonSvg = ``; + +const srcdoc = `${title}
${title}
${playButtonSvg}
`; +--- + + diff --git a/src/pages/design/embeds.mdx b/src/pages/design/embeds.mdx index f641f39..bc2d2fb 100644 --- a/src/pages/design/embeds.mdx +++ b/src/pages/design/embeds.mdx @@ -3,13 +3,57 @@ layout: '../../layouts/Page.astro' title: Embeds --- +import { Tweet, Vimeo, LinkPreview } from 'astro-embed'; +import YouTube from '../../components/YouTube.astro'; import Share from '../../components/Share.astro'; + +{/* for Twitter iframe */} +