Skip to content

Commit

Permalink
Merge pull request #172 from Suzu-Gears/support-CodePen-embed
Browse files Browse the repository at this point in the history
Support CodePen embed
  • Loading branch information
otoyo authored Nov 13, 2023
2 parents 17c8943 + a7234da commit 5726b1c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/notion-blocks/CodePenEmbed.astro
Original file line number Diff line number Diff line change
@@ -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]
---

<div class="codepen-embed">
<p
class="codepen"
data-height="500"
data-slug-hash={id.toString()}
data-user={user.toString()}
style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;"
>
</p>
</div>
<script async src="https://cpwebassets.codepen.io/assets/embed/ei.js"></script>

<style>
.codepen-embed {
background-color: #fff;
}
</style>
4 changes: 4 additions & 0 deletions src/components/notion-blocks/Embed.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +39,8 @@ try {
<InstagramEmbed url={url} />
) : isPinterestURL(url) ? (
<PinterestEmbed url={url} />
) : isCodePenURL(url) ? (
<CodePenEmbed url={url} />
) : (
<Bookmark block={block} urlMap={urlMap} />
)
Expand Down
7 changes: 7 additions & 0 deletions src/lib/blog-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit 5726b1c

@vercel
Copy link

@vercel vercel bot commented on 5726b1c Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

astro-notion-blog – ./

astro-notion-blog-taupe.vercel.app
astro-notion-blog-git-main-otoyo.vercel.app
astro-notion-blog-otoyo.vercel.app

Please sign in to comment.