Skip to content

Commit 4a9bd0b

Browse files
Fix youtube embed starting at specific timestamp
1 parent ab5554a commit 4a9bd0b

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
@@ -5,7 +5,7 @@ import { getTextContent } from 'notion-utils'
55
import { useNotionContext } from '../context'
66
import { LazyImage } from './lazy-image'
77
import { LiteYouTubeEmbed } from './lite-youtube-embed'
8-
import { getYoutubeId } from '../utils'
8+
import { getUrlParams, getYoutubeId } from '../utils'
99

1010
const isServer = typeof window === 'undefined'
1111

@@ -191,11 +191,13 @@ export const Asset: React.FC<{
191191
// console.log({ youtubeVideoId, src, format: block.format, style })
192192

193193
if (youtubeVideoId) {
194+
const params = getUrlParams(src)
194195
content = (
195196
<LiteYouTubeEmbed
196197
id={youtubeVideoId}
197198
style={assetStyle}
198199
className='notion-asset-object-fit'
200+
params={params}
199201
/>
200202
)
201203
} 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
@@ -82,3 +82,19 @@ export const getYoutubeId = (url: string): string | null => {
8282

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

0 commit comments

Comments
 (0)