fix: namespace pages are not created when using search to create

pull/2282/head
Tienson Qin 2021-06-24 10:55:15 +08:00
parent 3138ab08f7
commit 2f3811cbef
3 changed files with 21 additions and 24 deletions

View File

@ -271,10 +271,6 @@
:block/original-name path-page-name
:block/uuid (db/new-block-id)}]))
(db/pull [:block/name page-name])))
_ (when (and (not block?) (db/page-empty? (state/get-current-repo) (:db/id page)))
(page-handler/create! page-name {:page-map page
:redirect? false
:create-first-block? false}))
{:keys [title] :as properties} (:block/properties page)
page-name (:block/name page)
page-original-name (:block/original-name page)

View File

@ -278,8 +278,7 @@
(not (string/starts-with? p "../"))
(not (string/starts-with? p "./"))
(not (string/starts-with? p "http")))
;; Don't create the last page for now
(butlast (string/split p #"/"))))
(string/split p #"/")))
refs)
(remove string/blank?))
refs (->> (distinct (concat refs children-pages))

View File

@ -67,30 +67,32 @@
(defn create!
([title]
(create! title {}))
([title {:keys [redirect? page-map create-first-block?]
([title {:keys [redirect? create-first-block?]
:or {redirect? true
create-first-block? true}}]
(let [title (string/trim title)
pages (string/split title #"/")
page (string/lower-case title)
format (state/get-preferred-format)
tx (if page-map
page-map
(-> (block/page-name->map title true)
(assoc :block/format format)))
page-entity (if (:block/uuid tx)
[:block/uuid (:block/uuid tx)]
(:db/id tx))
create-title-property? (util/create-title-property? title)
default-properties (default-properties-block title format page-entity)
txs (if create-title-property?
[tx default-properties]
[tx])]
pages (map (fn [page]
(-> (block/page-name->map page true)
(assoc :block/format format)))
pages)
txs (mapcat
(fn [page]
(let [page-entity [:block/uuid (:block/uuid page)]
create-title-property? (util/create-title-property? (:block/name page))]
(if create-title-property?
(let [default-properties (default-properties-block (:block/original-name page) format page-entity)]
[page default-properties])
[page])))
pages)]
(db/transact! txs)
(when create-first-block?
(editor-handler/insert-first-page-block-if-not-exists! page))
(when redirect?
(route-handler/redirect! {:to :page
:path-params {:name page}})))))
(route-handler/redirect! {:to :page
:path-params {:name page}})))))
(defn page-add-property!
[page-name key value]
@ -235,9 +237,9 @@
(defn- walk-replace-old-page!
[form old-name new-name]
(walk/postwalk (fn [f] (if (string? f)
(if (= f old-name)
new-name
(replace-old-page! f old-name new-name))
(if (= f old-name)
new-name
(replace-old-page! f old-name new-name))
f)) form))
(defn rename!