Просмотр исходного кода

fix(android): share with no url

Andelf 3 лет назад
Родитель
Сommit
7bc26b7671

+ 1 - 1
src/main/frontend/mobile/intent.cljs

@@ -21,7 +21,7 @@
             [promesa.core :as p]))
 
 (defn- handle-received-text [args]
-  ;; {:title :type :url}
+  ;; :title :type :url
   (state/pub-event! [:editor/quick-capture args]))
 
 (defn- embed-asset-file [url format]

+ 23 - 7
src/main/frontend/quick_capture.cljs

@@ -11,18 +11,31 @@
             [frontend.util :as util]
             [frontend.util.text :as text-util]))
 
+(defn- is-tweet-link
+  [url]
+  (when (not-empty url)
+    (re-matches #"^https://twitter\.com/.*?/status/.*?$" url)))
+
+(defn- is-link
+  [url]
+  (when (not-empty url)
+    (re-matches #"^[a-zA-Z0-9]+://.*$" url)))
 
 (defn- extract-highlight
-  "Extract highlighted text and url from mobile browser intent share"
+  "Extract highlighted text and url from mobile browser intent share.
+   - url can be prefixed with the highlighted text.
+   - url can be highlighted text only in some cases."
   [url]
   (let [[_ highlight link] (re-matches #"(?s)\"(.*)\"\s+([a-z0-9]+://.*)$" url)]
-    (if (not-empty highlight)
+    (cond
+      (not-empty highlight)
       [highlight link]
-      [nil url])))
 
-(defn- is-tweet-link
-  [url]
-  (re-matches #"^https://twitter\.com/.*?/status/.*?$" url))
+      (is-link url)
+      [nil url]
+
+      :else
+      [url nil])))
 
 (defn quick-capture [args]
   (let [{:keys [url title content page append]} (bean/->clj args)
@@ -48,6 +61,9 @@
         time (date/get-current-time)
         text (or (and content (not-empty (string/trim content))) "")
         link (cond
+               (string/blank? url)
+               title
+
                (boolean (text-util/get-matched-video url))
                (str title " {{video " url "}}")
 
@@ -83,4 +99,4 @@
         (js/setTimeout #(editor-handler/api-insert-new-block! content {:page page
                                                                        :edit-block? true
                                                                        :replace-empty-target? true})
-                       100)))))
+                       100)))))

+ 5 - 4
src/main/frontend/util/text.cljs

@@ -14,10 +14,11 @@
 
 (defn get-matched-video
   [url]
-  (or (re-find youtube-regex url)
-      (re-find loom-regex url)
-      (re-find vimeo-regex url)
-      (re-find bilibili-regex url)))
+  (when (not-empty url)
+    (or (re-find youtube-regex url)
+        (re-find loom-regex url)
+        (re-find vimeo-regex url)
+        (re-find bilibili-regex url))))
 
 (defn build-data-value
   [col]