fix: Child namespace pages do not show up in hierarchy view if parent

page does not exist

Addresses #3641
pull/3686/head
Tienson Qin 2022-01-05 00:41:49 +08:00
parent 8cc194ce60
commit 704bcda9ad
8 changed files with 63 additions and 48 deletions

View File

@ -13,7 +13,8 @@
(defn get-relation
[page]
(when-let [page (or (text/get-nested-page-name page) page)]
(when (text/namespace-page? page)
(when (or (text/namespace-page? page)
(:block/_namespace (db/entity [:block/name (util/page-name-sanity-lc page)])))
(let [repo (state/get-current-repo)
namespace-pages (db/get-namespace-pages repo page)
parent-routes (db-model/get-page-namespace-routes repo page)

View File

@ -350,9 +350,7 @@
(when-not block?
[:div
(when (and
(not journal?)
(text/namespace-page? route-page-name))
(when (not journal?)
(hierarchy/structures route-page-name))
;; TODO: or we can lazy load them

View File

@ -67,8 +67,9 @@
(defn- delta-y
[e]
(let [rect (.. (.. e -target) getBoundingClientRect)]
(- (.. e -pageY) (.. rect -top))))
(when-let [target (.. e -target)]
(let [rect (.. target getBoundingClientRect)]
(- (.. e -pageY) (.. rect -top)))))
(defn- move-up?
[e]

View File

@ -121,6 +121,12 @@
(map (fn [tag] {:block/name (util/page-name-sanity-lc tag)
:block/original-name tag})
tags)))))
namespace-pages (let [page (:block/original-name page-entity)]
(when (text/namespace-page? page)
(->> (util/split-namespace-pages page)
(map (fn [page]
(-> (block/page-name->map page true)
(assoc :block/format format)))))))
pages (->> (concat
[page-entity]
@ref-pages
@ -128,9 +134,11 @@
(fn [page]
{:block/original-name page
:block/name (util/page-name-sanity-lc page)})
@ref-tags))
@ref-tags)
namespace-pages)
;; remove block references
(remove vector?))
(remove vector?)
(remove nil?))
pages (util/distinct-by :block/name pages)
block-ids (->>
(mapv (fn [block]

View File

@ -149,7 +149,7 @@
(defn- compute-new-file-path
[old-path new-name]
(let [result (string/split old-path "/")
file-name (util/page-name-sanity new-name)
file-name (util/page-name-sanity new-name true)
ext (last (string/split (last result) "."))
new-file (str file-name "." ext)
parts (concat (butlast result) [new-file])]
@ -359,8 +359,8 @@
"Only accepts unsanitized page names"
[old-name new-name redirect?]
(let [old-page-name (util/page-name-sanity-lc old-name)
new-file-name (util/page-name-sanity new-name)
new-page-name (string/lower-case new-file-name)
new-file-name (util/page-name-sanity new-name true)
new-page-name (util/page-name-sanity-lc new-name)
repo (state/get-current-repo)
page (db/pull [:block/name old-page-name])]
(when (and repo page)
@ -721,9 +721,12 @@
(config/get-file-extension format))
file-path (str "/" path)
repo-dir (config/get-repo-dir repo)]
(p/let [file-exists? (fs/file-exists? repo-dir file-path)]
(p/let [file-exists? (fs/file-exists? repo-dir file-path)
file-content (when file-exists?
(fs/read-file repo-dir file-path))]
(when (and (db/page-empty? repo today-page)
(not file-exists?))
(or (not file-exists?)
(and file-exists? (string/blank? file-content))))
(create! title {:redirect? false
:split-namespace? false
:create-first-block? (not template)

View File

@ -131,7 +131,7 @@
(if journal-page?
(date/journal-title->default title)
(-> (or (:block/original-name page) (:block/name page))
(util/page-name-sanity))) "."
(util/page-name-sanity true))) "."
(if (= format "markdown") "md" format))
file-path (str "/" path)
dir (config/get-repo-dir repo)]

View File

@ -1107,7 +1107,7 @@
(when (uuid-string? block-id)
(first (array-seq (js/document.getElementsByClassName block-id))))))))
(def windows-reserved-chars #"[\\/:\\*\\?\"<>|]+")
(def windows-reserved-chars #"[:\\*\\?\"<>|]+")
(defn include-windows-reserved-chars?
[s]
@ -1138,15 +1138,19 @@
(defn page-name-sanity
"Sanitize the page-name for file name"
[page-name]
(some-> page-name
([page-name]
(page-name-sanity page-name false))
([page-name replace-slash?]
(let [page (some-> page-name
(remove-boundary-slashes)
(string/replace #"/" ".")
;; Windows reserved path characters
(string/replace windows-reserved-chars "_")
;; for android filesystem compatiblity
(string/replace #"[\\#|%]+" "_")
(normalize)))
(normalize))]
(if replace-slash?
(string/replace page #"/" ".")
page))))
(defn page-name-sanity-lc
"Sanitize the query string for a page"