Skip to content

Commit 5726b1c

Browse files
authored
Merge pull request #172 from Suzu-Gears/support-CodePen-embed
Support CodePen embed
2 parents 17c8943 + a7234da commit 5726b1c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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>

src/components/notion-blocks/Embed.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import {
55
isTikTokURL,
66
isInstagramURL,
77
isPinterestURL,
8+
isCodePenURL,
89
} from '../../lib/blog-helpers.ts'
910
import Bookmark from './Bookmark.astro'
1011
import TweetEmbed from './TweetEmbed.astro'
1112
import TikTokEmbed from './TikTokEmbed.astro'
1213
import InstagramEmbed from './InstagramEmbed.astro'
1314
import PinterestEmbed from './PinterestEmbed.astro'
15+
import CodePenEmbed from './CodePenEmbed.astro'
1416
1517
export interface Props {
1618
block: interfaces.Block
@@ -37,6 +39,8 @@ try {
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
)

src/lib/blog-helpers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ export const isPinterestURL = (url: URL): boolean => {
220220
return /\/pin\/[\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 /\/[^/]+\/pen\/[^/]+/.test(url.pathname)
228+
}
229+
223230
export const isShortAmazonURL = (url: URL): boolean => {
224231
if (url.hostname === 'amzn.to' || url.hostname === 'www.amzn.to') {
225232
return true

0 commit comments

Comments
 (0)