Browse Source

fix: application erroring when entering a page reference

Close #2451
It's caused by :block/namespace doesn't have a UUID.
Also, this commit will only load several mime types.
Tienson Qin 4 years ago
parent
commit
f0d5ed118d

+ 13 - 10
src/electron/electron/utils.cljs

@@ -17,18 +17,21 @@
   [file]
   (last (string/split file #"\.")))
 
-;; TODO: ignore according to mime types
 (defn ignored-path?
   [dir path]
-  (or
-   (some #(string/starts-with? path (str dir "/" %))
-         ["." "assets" "node_modules"])
-   (some #(string/includes? path (str "/" % "/"))
-         ["." "assets" "node_modules"])
-   (let [path (string/lower-case path)]
-     (not
-      (some #(string/ends-with? path %)
-            [".md" ".markdown" ".org" ".edn" ".css"])))))
+  (when (string? path)
+    (or
+     (some #(string/starts-with? path (str dir "/" %))
+           ["." ".recycle" "assets" "node_modules"])
+     (some #(string/includes? path (str "/" % "/"))
+           ["." ".recycle" "assets" "node_modules"])
+     ;; hidden directory or file
+     (re-find #"/\.[^.]+" path)
+     (re-find #"^\.[^.]+" path)
+     (let [path (string/lower-case path)]
+       (not
+        (some #(string/ends-with? path %)
+              [".md" ".markdown" ".org" ".edn" ".css"]))))))
 
 (defn fix-win-path!
   [path]

+ 25 - 23
src/main/frontend/components/block.cljs

@@ -398,32 +398,34 @@
 
 (rum/defc page-preview-trigger
   [{:keys [children sidebar? tippy-position tippy-distance fixed-position? open? manual?] :as config} page-name]
-  (let [redirect-page-name (model/get-redirect-page-name page-name (:block/alias? config))
+  (let [redirect-page-name (or (model/get-redirect-page-name page-name (:block/alias? config))
+                               page-name)
         page-original-name (model/get-page-original-name redirect-page-name)
         debounced-open? (use-delayed-open open? page-name)
         html-template (fn []
-                        [:div.tippy-wrapper.overflow-y-auto.p-4
-                         {:style {:width          600
-                                  :text-align     "left"
-                                  :font-weight    500
-                                  :max-height     600
-                                  :padding-bottom 64}}
-                         (if (and (string? page-original-name) (string/includes? page-original-name "/"))
-                           [:div.my-2
-                            (->>
-                             (for [page (string/split page-original-name #"/")]
-                               (when (and (string? page) page)
-                                 (page-reference false page {} nil)))
-                             (interpose [:span.mx-2.opacity-30 "/"]))]
-                           [:h2.font-bold.text-lg (if (= page-name redirect-page-name)
-                                                    page-original-name
-                                                    [:span
-                                                     [:span.text-sm.mr-2 "Alias:"]
-                                                     page-original-name])])
-                         (let [page (db/entity [:block/name (string/lower-case redirect-page-name)])]
-                           (editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
-                           (when-let [f (state/get-page-blocks-cp)]
-                             (f (state/get-current-repo) page {:sidebar? sidebar? :preview? true})))])]
+                        (when redirect-page-name
+                          [:div.tippy-wrapper.overflow-y-auto.p-4
+                           {:style {:width          600
+                                    :text-align     "left"
+                                    :font-weight    500
+                                    :max-height     600
+                                    :padding-bottom 64}}
+                           (if (and (string? page-original-name) (string/includes? page-original-name "/"))
+                             [:div.my-2
+                              (->>
+                               (for [page (string/split page-original-name #"/")]
+                                 (when (and (string? page) page)
+                                   (page-reference false page {} nil)))
+                               (interpose [:span.mx-2.opacity-30 "/"]))]
+                             [:h2.font-bold.text-lg (if (= page-name redirect-page-name)
+                                                      page-original-name
+                                                      [:span
+                                                       [:span.text-sm.mr-2 "Alias:"]
+                                                       page-original-name])])
+                           (let [page (db/entity [:block/name (string/lower-case redirect-page-name)])]
+                             (editor-handler/insert-first-page-block-if-not-exists! redirect-page-name)
+                             (when-let [f (state/get-page-blocks-cp)]
+                               (f (state/get-current-repo) page {:sidebar? sidebar? :preview? true})))]))]
     (if (or (not manual?) open?)
       (ui/tippy {:html            html-template
                  :interactive     true

+ 2 - 1
src/main/frontend/components/repo.cljs

@@ -207,7 +207,8 @@
                [:span.repo-plus svg/plus]
                (let [repo-name (get-repo-name current-repo)
                      repo-name (if (util/electron?)
-                                 (last (string/split repo-name #"/"))
+                                 (last
+                                  (string/split repo-name #"/"))
                                  repo-name)]
                  [:span#repo-name repo-name])
                [:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]]])

+ 1 - 2
src/main/frontend/handler/extract.cljs

@@ -43,8 +43,7 @@
                                     (string? title)
                                     title))
             file-name (when-let [file-name (last (string/split file #"/"))]
-                        (-> (first (util/split-last "." file-name))
-                            (string/replace "." "/")))]
+                        (first (util/split-last "." file-name)))]
         (or property-name
             (if (= (state/page-name-order) "heading")
               (or first-block-name file-name)

+ 5 - 2
src/main/frontend/handler/web/nfs.cljs

@@ -26,8 +26,11 @@
 (defn remove-ignore-files
   [files]
   (let [files (remove (fn [f]
-                        (or (string/starts-with? (:file/path f) ".git/")
-                            (string/includes? (:file/path f) ".git/")))
+                        (let [path (:file/path f)]
+                          (or (string/starts-with? path ".git/")
+                              (string/includes? path ".git/")
+                              (and (util/ignored-path? "" path)
+                                   (not= (:file/name f) ".gitignore")))))
                       files)]
     (if-let [ignore-file (some #(when (= (:file/name %) ".gitignore")
                                   %) files)]

+ 7 - 1
src/main/frontend/modules/outliner/core.cljs

@@ -92,7 +92,13 @@
      (when-let [block-id (get-in this [:data :block/uuid])]
        block-id)
      (when-let [db-id (get-in this [:data :db/id])]
-       (:block/uuid (db/pull db-id)))))
+       (let [uuid (:block/uuid (db/pull db-id))]
+         (if uuid
+           uuid
+           (let [new-id (db/new-block-id)]
+             (db/transact! {:db/id db-id
+                            :block/uuid new-id})
+             new-id))))))
 
   (-get-parent-id [this]
     (-> (get-in this [:data :block/parent])

+ 17 - 0
src/main/frontend/util.cljc

@@ -1316,3 +1316,20 @@
    (defn meta-key-name []
      (let [user-agent (.. js/navigator -userAgent)]
        (if mac? "Cmd" "Ctrl"))))
+
+;; TODO: share with electron
+(defn ignored-path?
+  [dir path]
+  (when (string? path)
+    (or
+     (some #(string/starts-with? path (str dir "/" %))
+           ["." ".recycle" "assets" "node_modules"])
+     (some #(string/includes? path (str "/" % "/"))
+           ["." ".recycle" "assets" "node_modules"])
+     ;; hidden directory or file
+     (re-find #"/\.[^.]+" path)
+     (re-find #"^\.[^.]+" path)
+     (let [path (string/lower-case path)]
+       (not
+        (some #(string/ends-with? path %)
+              [".md" ".markdown" ".org" ".edn" ".css"]))))))