fix: markdown file references cause page blank

pull/3103/head
leizhe 2021-11-08 21:16:16 +08:00 committed by Tienson Qin
parent 4c70200c9d
commit b9b400fd13
2 changed files with 8 additions and 10 deletions

View File

@ -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+)"]

View File

@ -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))))