Skip to content

Commit 2745c39

Browse files
Merge pull request #320 from martin-lacko-rebood/fix-youtube-embed-with-specific-timestamp
2 parents 7442ba9 + b71a09e commit 2745c39

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/react-notion-x/src/components/asset.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type BaseContentBlock, type Block } from 'notion-types'
33
import { getTextContent } from 'notion-utils'
44

55
import { useNotionContext } from '../context'
6-
import { getYoutubeId } from '../utils'
6+
import { getUrlParams, getYoutubeId } from '../utils'
77
import { LazyImage } from './lazy-image'
88
import { LiteYouTubeEmbed } from './lite-youtube-embed'
99

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

215215
if (youtubeVideoId) {
216+
const params = getUrlParams(src)
216217
content = (
217218
<LiteYouTubeEmbed
218219
id={youtubeVideoId}
219220
style={assetStyle}
220221
className='notion-asset-object-fit'
222+
params={params}
221223
/>
222224
)
223225
} else if (block.type === 'gist') {

packages/react-notion-x/src/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,19 @@ export const getYoutubeId = (url: string): string | null => {
8383

8484
return null
8585
}
86+
87+
export const getUrlParams = (url: string): Record<string, string> | null => {
88+
try {
89+
const { searchParams } = new URL(url)
90+
const result: Record<string, string> = {}
91+
searchParams.forEach((value, key) => {
92+
result[key] = value
93+
})
94+
95+
return result
96+
} catch {
97+
// ignore invalid urls
98+
}
99+
100+
return null
101+
}

0 commit comments

Comments
 (0)