瀏覽代碼

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

Tienson Qin 4 年之前
父節點
當前提交
2f3811cbef
共有 3 個文件被更改,包括 21 次插入24 次删除
  1. 0 4
      src/main/frontend/components/page.cljs
  2. 1 2
      src/main/frontend/format/block.cljs
  3. 20 18
      src/main/frontend/handler/page.cljs

+ 0 - 4
src/main/frontend/components/page.cljs

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

+ 1 - 2
src/main/frontend/format/block.cljs

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

+ 20 - 18
src/main/frontend/handler/page.cljs

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