enhance(editor): support time offset of youtube links

Close #10927
pull/10962/head
Andelf 2024-02-01 23:46:06 +08:00
parent c3df737390
commit 3dd8a849c8
2 changed files with 11 additions and 4 deletions

View File

@ -1353,7 +1353,10 @@
url)]
(if (and (coll? src)
(= (first src) "youtube-player"))
(youtube/youtube-video (last src) nil)
(let [t (re-find #"&t=(\d+)" url)
opts (when (seq t)
{:start (nth t 1)})]
(youtube/youtube-video (last src) opts))
(when src
(let [width (min (- (util/get-width) 96) 560)
height (int (* width (/ (if (string/includes? src "player.bilibili.com")

View File

@ -51,16 +51,20 @@
(<! (load-youtube-api))
(register-player state))
state)}
[state id {:keys [width height] :as _opts}]
[state id {:keys [width height start] :as _opts}]
(let [width (or width (min (- (util/get-width) 96)
560))
height (or height (int (* width (/ 315 560))))]
height (or height (int (* width (/ 315 560))))
url (str "https://www.youtube.com/embed/" id "?enablejsapi=1")
url (if start
(str url "&start=" start)
url)]
[:iframe
{:id (str "youtube-player-" id)
:allow-full-screen "allowfullscreen"
:allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope"
:frame-border "0"
:src (str "https://www.youtube.com/embed/" id "?enablejsapi=1")
:src url
:height height
:width width}]))