mirror of https://github.com/logseq/logseq
ux: copy logseq URL of block
parent
724eb92990
commit
dd7cc6a70f
|
@ -131,7 +131,7 @@
|
|||
(let [params (.-searchParams parsed-url)]
|
||||
(map (fn [key]
|
||||
(when-let [value (.get params key)]
|
||||
(js/decodeURI value)))
|
||||
(js/decodeURIComponent value)))
|
||||
keys)))
|
||||
|
||||
;; Keep update with the normalization in main
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
[frontend.components.editor :as editor]
|
||||
[frontend.components.page-menu :as page-menu]
|
||||
[frontend.components.export :as export]
|
||||
[frontend.components.repo :as repo]
|
||||
[frontend.config :as config]
|
||||
[frontend.context.i18n :refer [t]]
|
||||
[frontend.db :as db]
|
||||
|
@ -21,6 +22,7 @@
|
|||
[frontend.state :as state]
|
||||
[frontend.ui :as ui]
|
||||
[frontend.util :as util]
|
||||
[frontend.util.url :as url-util]
|
||||
[goog.dom :as gdom]
|
||||
[goog.object :as gobj]
|
||||
[rum.core :as rum]))
|
||||
|
@ -211,6 +213,19 @@
|
|||
:on-click (fn [_e]
|
||||
(editor-handler/copy-block-ref! block-id #(util/format "{{embed ((%s))}}" %)))}
|
||||
"Copy block embed")
|
||||
|
||||
;; TODO Logseq protocol mobile support
|
||||
(when (util/electron?)
|
||||
(ui/menu-link
|
||||
{:key "Copy block URL"
|
||||
:on-click (fn [_e]
|
||||
(let [current-repo (state/get-current-repo)
|
||||
repo-path (repo/get-repo-name current-repo)
|
||||
short-repo-name (repo/get-short-repo-name repo-path)
|
||||
tap-f (fn [block-id]
|
||||
(url-util/get-local-logseq-url-by-uuid short-repo-name block-id))]
|
||||
(editor-handler/copy-block-ref! block-id tap-f)))}
|
||||
"Copy block URL"))
|
||||
|
||||
(block-template block-id)
|
||||
|
||||
|
|
|
@ -183,7 +183,8 @@
|
|||
(p/let [multiple-windows? (ipc/ipc "graphHasMultipleWindows" (state/get-current-repo))]
|
||||
(reset! (::electron-multiple-windows? state) multiple-windows?))))
|
||||
|
||||
(defn- get-repo-name [repo]
|
||||
;; TODO move to else where?
|
||||
(defn get-repo-name [repo]
|
||||
(cond
|
||||
(mobile-util/is-native-platform?)
|
||||
(text/get-graph-name-from-path repo)
|
||||
|
@ -194,6 +195,15 @@
|
|||
:else
|
||||
(db/get-repo-path repo)))
|
||||
|
||||
;; TODO move to else where?
|
||||
(defn get-short-repo-name
|
||||
"repo-path: output of `get-repo-name`"
|
||||
[repo-path]
|
||||
(if (or (util/electron?)
|
||||
(mobile-util/is-native-platform?))
|
||||
(text/get-file-basename repo-path)
|
||||
repo-path))
|
||||
|
||||
(defn- repos-dropdown-links [repos current-repo *multiple-windows?]
|
||||
(let [switch-repos (remove (fn [repo] (= current-repo (:url repo))) repos) ; exclude current repo
|
||||
repo-links (mapv
|
||||
|
@ -274,10 +284,7 @@
|
|||
links (repos-dropdown-links repos current-repo multiple-windows?)
|
||||
render-content (fn [{:keys [toggle-fn]}]
|
||||
(let [repo-path (get-repo-name current-repo)
|
||||
short-repo-name (if (or (util/electron?)
|
||||
(mobile-util/is-native-platform?))
|
||||
(text/get-file-basename repo-path)
|
||||
repo-path)]
|
||||
short-repo-name (get-short-repo-name repo-path)]
|
||||
[:a.item.group.flex.items-center.px-2.py-2.text-sm.font-medium.rounded-md
|
||||
{:on-click (fn []
|
||||
(check-multiple-windows? state)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
(ns frontend.util.url)
|
||||
|
||||
;; Keep same as electron/core.cljs
|
||||
(def LSP_SCHEME "logseq")
|
||||
(def encoder js/encodeURIComponent)
|
||||
|
||||
(defn get-logseq-url-by-uuid
|
||||
"Only the name of repo is required (not full path)"
|
||||
[host repo-name uuid]
|
||||
(str LSP_SCHEME "://" host "/open?graph=" (encoder repo-name) "&block-id=" uuid))
|
||||
|
||||
(defn get-local-logseq-url-by-uuid
|
||||
"Ensure repo-name and uuid are valid string before hand.
|
||||
Only the name of repo is required (not full path)"
|
||||
[repo-name uuid]
|
||||
(get-logseq-url-by-uuid "local" repo-name uuid))
|
Loading…
Reference in New Issue