Skip to content

Commit

Permalink
Merge pull request #320 from martin-lacko-rebood/fix-youtube-embed-wi…
Browse files Browse the repository at this point in the history
…th-specific-timestamp
  • Loading branch information
transitive-bullshit authored Nov 1, 2024
2 parents 7442ba9 + b71a09e commit 2745c39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/react-notion-x/src/components/asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type BaseContentBlock, type Block } from 'notion-types'
import { getTextContent } from 'notion-utils'

import { useNotionContext } from '../context'
import { getYoutubeId } from '../utils'
import { getUrlParams, getYoutubeId } from '../utils'
import { LazyImage } from './lazy-image'
import { LiteYouTubeEmbed } from './lite-youtube-embed'

Expand Down Expand Up @@ -213,11 +213,13 @@ export function Asset({
// console.log({ youtubeVideoId, src, format: block.format, style })

if (youtubeVideoId) {
const params = getUrlParams(src)
content = (
<LiteYouTubeEmbed
id={youtubeVideoId}
style={assetStyle}
className='notion-asset-object-fit'
params={params}
/>
)
} else if (block.type === 'gist') {
Expand Down
16 changes: 16 additions & 0 deletions packages/react-notion-x/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@ export const getYoutubeId = (url: string): string | null => {

return null
}

export const getUrlParams = (url: string): Record<string, string> | null => {
try {
const { searchParams } = new URL(url)
const result: Record<string, string> = {}
searchParams.forEach((value, key) => {
result[key] = value
})

return result
} catch {
// ignore invalid urls
}

return null
}

0 comments on commit 2745c39

Please sign in to comment.