Browse Source

don't create new contents file when changing format

Logseq now creates a new contents file when users try to toggle the
preferred format, which causes file duplications error.
llcc 3 years ago
parent
commit
b7b73613db
1 changed files with 17 additions and 14 deletions
  1. 17 14
      src/main/frontend/handler/repo.cljs

+ 17 - 14
src/main/frontend/handler/repo.cljs

@@ -51,20 +51,23 @@
 (defn create-contents-file
   [repo-url]
   (spec/validate :repos/url repo-url)
-  (let [repo-dir (config/get-repo-dir repo-url)
-        format (state/get-preferred-format)
-        path (str (state/get-pages-directory)
-                  "/contents."
-                  (config/get-file-extension format))
-        file-path (str "/" path)
-        default-content (case (name format)
-                          "org" (rc/inline "contents.org")
-                          "markdown" (rc/inline "contents.md")
-                          "")]
-    (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" (state/get-pages-directory)))
-            file-exists? (fs/create-if-not-exists repo-url repo-dir file-path default-content)]
-      (when-not file-exists?
-        (file-handler/reset-file! repo-url path default-content)))))
+  (p/let [repo-dir (config/get-repo-dir repo-url)
+          pages-dir (state/get-pages-directory)
+          [org-path md-path] (map #(str "/" pages-dir "/contents." %) ["org" "md"])
+          contents-file-exist? (some #(fs/file-exists? repo-dir %) [org-path md-path])]
+    (when-not contents-file-exist?
+      (let [format (state/get-preferred-format)
+            path (str pages-dir "/contents."
+                      (config/get-file-extension format))
+            file-path (str "/" path)
+            default-content (case (name format)
+                              "org" (rc/inline "contents.org")
+                              "markdown" (rc/inline "contents.md")
+                              "")]
+        (p/let [_ (fs/mkdir-if-not-exists (str repo-dir "/" pages-dir))
+                file-exists? (fs/create-if-not-exists repo-url repo-dir file-path default-content)]
+          (when-not file-exists?
+            (file-handler/reset-file! repo-url path default-content)))))))
 
 (defn create-custom-theme
   [repo-url]