From b9b400fd1378a63a89dea2e7dda184f76b04cbcf Mon Sep 17 00:00:00 2001 From: leizhe Date: Mon, 8 Nov 2021 21:16:16 +0800 Subject: [PATCH] fix: markdown file references cause page blank --- src/main/frontend/components/block.cljs | 13 ++++--------- src/main/frontend/text.cljs | 5 ++++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 3cca5b84d..643f614f4 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -920,11 +920,8 @@ :else (let [href (string-of-url url) - protocol (or - (and (= "Complex" (first url)) - (:protocol (second url))) - (and (= "File" (first url)) - "file"))] + [protocol path] (or (and (= "Complex" (first url)) url) + (and (= "File" (first url)) ["file" (second url)]))] (cond (and (= (get-in config [:block :block/format]) :org) (= "Complex" (first url)) @@ -949,10 +946,9 @@ (asset-reference config label href) :else - (let [label-text (get-label-text label) - redirect-page-name (-> (second url) - text/get-file-basename) + (let [redirect-page-name (when (string? path) (text/get-file-basename path)) config (assoc config :redirect-page-name redirect-page-name) + label-text (get-label-text label) page (if (string/blank? label-text) {:block/name (db/get-file-page (string/replace href "file:" ""))} (get-page label))] @@ -1174,7 +1170,6 @@ :width width :height (max 500 height)}]))))) - (contains? #{"tweet" "twitter"} name) (when-let [url (first arguments)] (let [id-regex #"/status/(\d+)"] diff --git a/src/main/frontend/text.cljs b/src/main/frontend/text.cljs index 4968018f9..178306f7c 100644 --- a/src/main/frontend/text.cljs +++ b/src/main/frontend/text.cljs @@ -7,6 +7,7 @@ (def page-ref-re-0 #"\[\[(.*)\]\]") (def org-page-ref-re #"\[\[(file:.*)\]\[.+?\]\]") +(def markdown-page-ref-re #"\[(.*)\]\(file:.*\)") (defn get-file-basename [path] @@ -16,7 +17,9 @@ (defn get-page-name [s] (and (string? s) - (or (when-let [[_ path _label] (re-matches org-page-ref-re s)] + (or (when-let [[_ label _path] (re-matches markdown-page-ref-re s)] + (string/trim label)) + (when-let [[_ path _label] (re-matches org-page-ref-re s)] (get-file-basename path)) (-> (re-matches page-ref-re-0 s) second))))