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 (defn get-relation
[page] [page]
(when-let [page (or (text/get-nested-page-name page) 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) (let [repo (state/get-current-repo)
namespace-pages (db/get-namespace-pages repo page) namespace-pages (db/get-namespace-pages repo page)
parent-routes (db-model/get-page-namespace-routes repo page) parent-routes (db-model/get-page-namespace-routes repo page)

View File

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

View File

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

View File

@ -121,6 +121,12 @@
(map (fn [tag] {:block/name (util/page-name-sanity-lc tag) (map (fn [tag] {:block/name (util/page-name-sanity-lc tag)
:block/original-name tag}) :block/original-name tag})
tags))))) 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 pages (->> (concat
[page-entity] [page-entity]
@ref-pages @ref-pages
@ -128,9 +134,11 @@
(fn [page] (fn [page]
{:block/original-name page {:block/original-name page
:block/name (util/page-name-sanity-lc page)}) :block/name (util/page-name-sanity-lc page)})
@ref-tags)) @ref-tags)
namespace-pages)
;; remove block references ;; remove block references
(remove vector?)) (remove vector?)
(remove nil?))
pages (util/distinct-by :block/name pages) pages (util/distinct-by :block/name pages)
block-ids (->> block-ids (->>
(mapv (fn [block] (mapv (fn [block]

View File

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

View File

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

View File

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