Browse Source

enhance: deprecate :journal/file-name-format for db graphs

Confirmed all uses of it are file only and fixed a case where db graph
could've accidentally used it (by having org-mode configured)
Gabriel Horner 5 months ago
parent
commit
7319e1541c

+ 1 - 0
deps/common/resources/templates/config.edn

@@ -38,6 +38,7 @@
  ;;   This configuration is not retroactive and affects only new journals.
  ;;   To show old journal files in the app, manually rename the files in the
  ;;   journal directory to match the new format.
+ ;; This is _only_ for file graphs.
  ;; Default value: "yyyy_MM_dd"
  ;; :journal/file-name-format "yyyy_MM_dd"
 

+ 1 - 0
src/main/frontend/handler/common/config_edn.cljs

@@ -94,6 +94,7 @@ nested keys or positional errors e.g. tuples"
      :file-sync/ignore-files
      :hidden
      :ignored-page-references-keywords
+     :journal/file-name-format
      :journal/page-title-format
      :journals-directory
      :logbook/settings

+ 56 - 0
src/main/frontend/handler/file_based/page.cljs

@@ -0,0 +1,56 @@
+(ns frontend.handler.file-based.page
+  (:require [clojure.string :as string]
+            [frontend.config :as config]
+            [frontend.date :as date]
+            [frontend.db :as db]
+            [frontend.db.model :as model]
+            [frontend.handler.common.page :as page-common-handler]
+            [frontend.mobile.util :as mobile-util]
+            [frontend.state :as state]
+            [frontend.util :as util]
+            [logseq.common.util :as common-util]
+            [logseq.common.util.page-ref :as page-ref]))
+
+;; FIXME: add whiteboard
+(defn- get-directory
+  [journal?]
+  (if journal?
+    (config/get-journals-directory)
+    (config/get-pages-directory)))
+
+(defn- get-file-name
+  [journal? title]
+  (when-let [s (if journal?
+                 (date/journal-title->default title)
+                 ;; legacy in org-mode format, don't escape slashes except bug reported
+                 (common-util/page-name-sanity (string/lower-case title)))]
+    ;; Win10 file path has a length limit of 260 chars
+    (common-util/safe-subs s 0 200)))
+
+(defn get-page-ref-text
+  [page]
+  (let [edit-block-file-path (model/get-block-file-path (state/get-edit-block))
+        page-name (string/lower-case page)]
+    (if (and edit-block-file-path
+             (state/org-mode-file-link? (state/get-current-repo)))
+      (if-let [ref-file-path (:file/path (db/get-page-file page-name))]
+        (util/format "[[file:%s][%s]]"
+                     (util/get-relative-path edit-block-file-path ref-file-path)
+                     page)
+        (let [journal? (date/valid-journal-title? page)
+              ref-file-path (str
+                             (if (or (util/electron?) (mobile-util/native-platform?))
+                               (-> (config/get-repo-dir (state/get-current-repo))
+                                   js/decodeURI
+                                   (string/replace #"/+$" "")
+                                   (str "/"))
+                               "")
+                             (get-directory journal?)
+                             "/"
+                             (get-file-name journal? page)
+                             ".org")]
+          (page-common-handler/<create! page {:redirect? false})
+          (util/format "[[file:%s][%s]]"
+                       (util/get-relative-path edit-block-file-path ref-file-path)
+                       page)))
+      (page-ref/->page-ref page))))

+ 4 - 41
src/main/frontend/handler/page.cljs

@@ -18,6 +18,7 @@
             [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.file-based.nfs :as nfs-handler]
+            [frontend.handler.file-based.page :as file-page-handler]
             [frontend.handler.file-based.page-property :as file-page-property]
             [frontend.handler.graph :as graph-handler]
             [frontend.handler.notification :as notification]
@@ -92,22 +93,6 @@
                               (distinct))]
           (keep (fn [page-name] (db/get-page page-name)) page-names))))))
 
-;; FIXME: add whiteboard
-(defn- get-directory
-  [journal?]
-  (if journal?
-    (config/get-journals-directory)
-    (config/get-pages-directory)))
-
-(defn- get-file-name
-  [journal? title]
-  (when-let [s (if journal?
-                 (date/journal-title->default title)
-                 ;; legacy in org-mode format, don't escape slashes except bug reported
-                 (common-util/page-name-sanity (string/lower-case title)))]
-    ;; Win10 file path has a length limit of 260 chars
-    (common-util/safe-subs s 0 200)))
-
 (defn toggle-favorite! []
   ;; NOTE: in journals or settings, current-page is nil
   (when-let [page-name (state/get-current-page)]
@@ -159,31 +144,9 @@
 
 (defn get-page-ref-text
   [page]
-  (let [edit-block-file-path (model/get-block-file-path (state/get-edit-block))
-        page-name (string/lower-case page)]
-    (if (and edit-block-file-path
-             (state/org-mode-file-link? (state/get-current-repo)))
-      (if-let [ref-file-path (:file/path (db/get-page-file page-name))]
-        (util/format "[[file:%s][%s]]"
-                     (util/get-relative-path edit-block-file-path ref-file-path)
-                     page)
-        (let [journal? (date/valid-journal-title? page)
-              ref-file-path (str
-                             (if (or (util/electron?) (mobile-util/native-platform?))
-                               (-> (config/get-repo-dir (state/get-current-repo))
-                                   js/decodeURI
-                                   (string/replace #"/+$" "")
-                                   (str "/"))
-                               "")
-                             (get-directory journal?)
-                             "/"
-                             (get-file-name journal? page)
-                             ".org")]
-          (<create! page {:redirect? false})
-          (util/format "[[file:%s][%s]]"
-                       (util/get-relative-path edit-block-file-path ref-file-path)
-                       page)))
-      (page-ref/->page-ref page))))
+  (if (config/db-based-graph?)
+    (page-ref/->page-ref page)
+    (file-page-handler/get-page-ref-text page)))
 
 (defn init-commands!
   []