Skip to content

Commit

Permalink
fix bilibili embed issues
Browse files Browse the repository at this point in the history
1. fix logseq#5820
2. fix logseq#5811
  • Loading branch information
llcc authored and tiensonqin committed Jun 27, 2022
1 parent ca52df9 commit 292bda9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,7 @@
(defn- macro-video-cp
[_config arguments]
(when-let [url (first arguments)]
(let [width (min (- (util/get-width) 96)
560)
height (int (* width (/ 315 560)))
results (text-util/get-matched-video url)
(let [results (text-util/get-matched-video url)
src (match results
[_ _ _ (:or "youtube.com" "youtu.be" "y2u.be") _ id _]
(if (= (count id) 11) ["youtube-player" id] url)
Expand All @@ -1170,25 +1167,31 @@
[_ _ _ (_ :guard #(string/ends-with? % "vimeo.com")) _ id _]
(str "https://player.vimeo.com/video/" id)

[_ _ _ "bilibili.com" _ id _]
(str "https://player.bilibili.com/player.html?bvid=" id "&high_quality=1")
[_ _ _ "bilibili.com" _ id & query]
(str "https://player.bilibili.com/player.html?bvid=" id "&high_quality=1"
(when-let [page (second query)]
(str "&page=" page)))

:else
url)]
(if (and (coll? src)
(= (first src) "youtube-player"))
(youtube/youtube-video (last src))
(when src
[:iframe
{:allowfullscreen true
:allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope"
:framespacing "0"
:frameborder "no"
:border "0"
:scrolling "no"
:src src
:width width
:height height}])))))
(let [width (min (- (util/get-width) 96) 560)
height (int (* width (/ (if (string/includes? src "player.bilibili.com")
360 315)
560)))]
[:iframe
{:allow-full-screen true
:allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope"
:framespacing "0"
:frame-border "no"
:border "0"
:scrolling "no"
:src src
:width width
:height height}]))))))

(defn- macro-else-cp
[name config arguments]
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/util/text.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

(defonce between-re #"\(between ([^\)]+)\)")

(def bilibili-regex #"^((?:https?:)?//)?((?:www).)?((?:bilibili.com))(/(?:video/)?)([\w-]+)(\S+)?$")
(def bilibili-regex #"^((?:https?:)?//)?((?:www).)?((?:bilibili.com))(/(?:video/)?)([\w-]+)(\?p=(\d+))?(\S+)?$")
(def loom-regex #"^((?:https?:)?//)?((?:www).)?((?:loom.com))(/(?:share/|embed/))([\w-]+)(\S+)?$")
(def vimeo-regex #"^((?:https?:)?//)?((?:www).)?((?:player.vimeo.com|vimeo.com))(/(?:video/)?)([\w-]+)(\S+)?$")
(def youtube-regex #"^((?:https?:)?//)?((?:www|m).)?((?:youtube.com|youtu.be|y2u.be|youtube-nocookie.com))(/(?:[\w-]+\?v=|embed/|v/)?)([\w-]+)([\S^\?]+)?$")
Expand Down

0 comments on commit 292bda9

Please sign in to comment.