File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ export interface Props {
3+ url: string
4+ }
5+ const { url } = Astro .props
6+ const user = url .pathname .split (' /' )[1 ]
7+ const id = url .pathname .split (' /' )[3 ]
8+ ---
9+
10+ <div class =" codepen-embed" >
11+ <p
12+ class =" codepen"
13+ data-height =" 500"
14+ data-slug-hash ={ id .toString ()}
15+ data-user ={ user .toString ()}
16+ style =" height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;"
17+ >
18+ </p >
19+ </div >
20+ <script async src =" https://cpwebassets.codepen.io/assets/embed/ei.js" ></script >
21+
22+ <style >
23+ .codepen-embed {
24+ background-color: #fff;
25+ }
26+ </style >
Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ import {
55 isTikTokURL ,
66 isInstagramURL ,
77 isPinterestURL ,
8+ isCodePenURL ,
89} from ' ../../lib/blog-helpers.ts'
910import Bookmark from ' ./Bookmark.astro'
1011import TweetEmbed from ' ./TweetEmbed.astro'
1112import TikTokEmbed from ' ./TikTokEmbed.astro'
1213import InstagramEmbed from ' ./InstagramEmbed.astro'
1314import PinterestEmbed from ' ./PinterestEmbed.astro'
15+ import CodePenEmbed from ' ./CodePenEmbed.astro'
1416
1517export interface Props {
1618 block: interfaces .Block
3739 <InstagramEmbed url = { url } />
3840 ) : isPinterestURL (url ) ? (
3941 <PinterestEmbed url = { url } />
42+ ) : isCodePenURL (url ) ? (
43+ <CodePenEmbed url = { url } />
4044 ) : (
4145 <Bookmark block = { block } urlMap = { urlMap } />
4246 )
Original file line number Diff line number Diff line change @@ -220,6 +220,13 @@ export const isPinterestURL = (url: URL): boolean => {
220220 return / \/ p i n \/ [ \d ] + / . test ( url . pathname )
221221}
222222
223+ export const isCodePenURL = ( url : URL ) : boolean => {
224+ if ( url . hostname !== 'codepen.io' && url . hostname !== 'www.codepen.io' ) {
225+ return false
226+ }
227+ return / \/ [ ^ / ] + \/ p e n \/ [ ^ / ] + / . test ( url . pathname )
228+ }
229+
223230export const isShortAmazonURL = ( url : URL ) : boolean => {
224231 if ( url . hostname === 'amzn.to' || url . hostname === 'www.amzn.to' ) {
225232 return true
You can’t perform that action at this time.
0 commit comments