diff --git a/src/main/frontend/mobile/intent.cljs b/src/main/frontend/mobile/intent.cljs index 9f7520fd32..035cc3b4fe 100644 --- a/src/main/frontend/mobile/intent.cljs +++ b/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] diff --git a/src/main/frontend/quick_capture.cljs b/src/main/frontend/quick_capture.cljs index 6afe8d143f..fecbb93cac 100644 --- a/src/main/frontend/quick_capture.cljs +++ b/src/main/frontend/quick_capture.cljs @@ -11,18 +11,31 @@ [frontend.util :as util] [frontend.util.text :as text-util])) - -(defn- extract-highlight - "Extract highlighted text and url from mobile browser intent share" - [url] - (let [[_ highlight link] (re-matches #"(?s)\"(.*)\"\s+([a-z0-9]+://.*)$" url)] - (if (not-empty highlight) - [highlight link] - [nil url]))) - (defn- is-tweet-link [url] - (re-matches #"^https://twitter\.com/.*?/status/.*?$" 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. + - 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)] + (cond + (not-empty highlight) + [highlight link] + + (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))))) \ No newline at end of file + 100))))) diff --git a/src/main/frontend/util/text.cljs b/src/main/frontend/util/text.cljs index e2c5e5d3b1..57b7425ac8 100644 --- a/src/main/frontend/util/text.cljs +++ b/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]