Browse Source

commands: add vimeo video embed block command

Collin Lefeber 4 years ago
parent
commit
dfb0ff6bd3
2 changed files with 21 additions and 0 deletions
  1. 4 0
      src/main/frontend/commands.cljs
  2. 17 0
      src/main/frontend/components/block.cljs

+ 4 - 0
src/main/frontend/commands.cljs

@@ -138,6 +138,10 @@
 
      ["Embed Youtube Video" [[:editor/input "{{youtube }}" {:last-pattern slash
                                                             :backward-pos 2}]]]
+
+     ["Embed Vimeo Video" [[:editor/input "{{vimeo }}" {:last-pattern slash
+                                                        :backward-pos 2}]]]
+
      ["Html Inline " (->inline "html")]
 
      ;; TODO:

+ 17 - 0
src/main/frontend/components/block.cljs

@@ -800,6 +800,23 @@
                     :height height
                     :width width}])))))
 
+        (= name "vimeo")
+        (let [url (first arguments)]
+          (let [Vimeo-regex #"^((?:https?:)?//)?((?:www).)?((?:player.vimeo.com|vimeo.com)?)((?:/video/)?)([\w-]+)(\S+)?$"]
+            (when-let [vimeo-id (nth (re-find Vimeo-regex url) 5)]
+              (when-not (string/blank? vimeo-id)
+                (let [width (min (- (util/get-width) 96)
+                                 560)
+                      height (int (* width (/ 315 560)))]
+                  [:iframe
+                   {:allow-full-screen "allowfullscreen"
+                    :allow
+                    "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
+                    :frame-border "0"
+                    :src (str "https://player.vimeo.com/video/" vimeo-id)
+                    :height height
+                    :width width}])))))
+
         ;; TODO: support fullscreen mode, maybe we need a fullscreen dialog?
         (= name "bilibili")
         (let [url (first arguments)