diff --git a/src/components/notion-blocks/CodePenEmbed.astro b/src/components/notion-blocks/CodePenEmbed.astro new file mode 100644 index 000000000..90f652a95 --- /dev/null +++ b/src/components/notion-blocks/CodePenEmbed.astro @@ -0,0 +1,26 @@ +--- +export interface Props { + url: string +} +const { url } = Astro.props +const user = url.pathname.split('/')[1] +const id = url.pathname.split('/')[3] +--- + +
+

+

+
+ + + diff --git a/src/components/notion-blocks/Embed.astro b/src/components/notion-blocks/Embed.astro index ca7a54e9c..ba5b78aba 100644 --- a/src/components/notion-blocks/Embed.astro +++ b/src/components/notion-blocks/Embed.astro @@ -5,12 +5,14 @@ import { isTikTokURL, isInstagramURL, isPinterestURL, + isCodePenURL, } from '../../lib/blog-helpers.ts' import Bookmark from './Bookmark.astro' import TweetEmbed from './TweetEmbed.astro' import TikTokEmbed from './TikTokEmbed.astro' import InstagramEmbed from './InstagramEmbed.astro' import PinterestEmbed from './PinterestEmbed.astro' +import CodePenEmbed from './CodePenEmbed.astro' export interface Props { block: interfaces.Block @@ -37,6 +39,8 @@ try { ) : isPinterestURL(url) ? ( + ) : isCodePenURL(url) ? ( + ) : ( ) diff --git a/src/lib/blog-helpers.ts b/src/lib/blog-helpers.ts index 4e14156d5..8d7b6ae57 100644 --- a/src/lib/blog-helpers.ts +++ b/src/lib/blog-helpers.ts @@ -220,6 +220,13 @@ export const isPinterestURL = (url: URL): boolean => { return /\/pin\/[\d]+/.test(url.pathname) } +export const isCodePenURL = (url: URL): boolean => { + if (url.hostname !== 'codepen.io' && url.hostname !== 'www.codepen.io') { + return false + } + return /\/[^/]+\/pen\/[^/]+/.test(url.pathname) +} + export const isShortAmazonURL = (url: URL): boolean => { if (url.hostname === 'amzn.to' || url.hostname === 'www.amzn.to') { return true