fix: link property causes wrong pages creation

pull/3963/head
llcc 2022-03-06 19:10:50 +08:00 committed by Tienson Qin
parent 965bedf4fa
commit f02c21c95b
3 changed files with 23 additions and 6 deletions

View File

@ -159,7 +159,8 @@
(contains? #{:background-color :background_color} (keyword k))))
(map last)
(map (fn [v]
(when (string? v)
(when (and (string? v)
(not (mldoc/link? format v)))
(let [v (string/trim v)
result (text/split-page-refs-without-brackets v {:un-brackets? false})]
(if (coll? result)

View File

@ -8,7 +8,8 @@
[lambdaisland.glogi :as log]
[medley.core :as medley]
["mldoc" :as mldoc :refer [Mldoc]]
[linked.core :as linked]))
[linked.core :as linked]
[frontend.config :as config]))
(defonce parseJson (gobj/get Mldoc "parseJson"))
(defonce parseInlineJson (gobj/get Mldoc "parseInlineJson"))
@ -263,6 +264,17 @@
(defn link?
[format link]
(when (string? link)
(let [[type link] (first (inline->edn link (default-config format)))]
(let [[type link] (first (inline->edn link (default-config format)))
[ref-type ref-value] (:url link)]
(and (= "Link" type)
(not (contains? #{"Page_ref" "Block_ref"} (first (:url link))))))))
(or
;; 1. url
(not (contains? #{"Page_ref" "Block_ref"} ref-type))
(and (contains? #{"Page_ref"} ref-type)
(or
;; 2. excalidraw link
(config/draw? ref-value)
;; 3. local asset link
(boolean (config/local-asset? ref-value)))))))))

View File

@ -22,12 +22,16 @@
(testing "org links without labels"
(are [x y] (= (mldoc/link? :org x) y)
"[[http://www.google.com]]" true
"[[https://www.google.com]]" true))
"[[https://www.google.com]]" true
"[[draws/2022-03-06-15-00-28.excalidraw]]" true
"[[assets/2022-03-06-15-00-28.pdf]]" true))
(testing "markdown links"
(are [x y] (= (mldoc/link? :markdown x) y)
"[google](http://www.google.com)" true
"[google](https://www.google.com)" true))
"[google](https://www.google.com)" true
"[[draws/2022-03-06-15-00-28.excalidraw]]" true
"![a pdf](assets/2022-03-06-15-00-28.pdf)" true))
;; https://github.com/logseq/logseq/issues/4308
(testing "parsing links should be finished"