diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 153885f6e8..802756cfca 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -71,7 +71,6 @@ electron.utils utils frontend.commands commands frontend.common.date common-date - frontend.common.file.util wfu frontend.common.missionary-util c.m frontend.common.schema-register sr frontend.common.search-fuzzy fuzzy diff --git a/deps/common/resources/templates/config.edn b/deps/common/resources/templates/config.edn index bcec00aa3e..74e2448fae 100644 --- a/deps/common/resources/templates/config.edn +++ b/deps/common/resources/templates/config.edn @@ -1,135 +1,5 @@ {:meta/version 1 - ;; == FILE GRAPH CONFIG == - ;; - ;; Set the preferred format. - ;; This is _only_ for file graphs. - ;; Available options: - ;; - Markdown (default) - ;; - Org - ;; :preferred-format "Markdown" - - ;; Set the preferred workflow style. - ;; This is _only_ for file graphs. - ;; Available options: - ;; - :now for NOW/LATER style (default) - ;; - :todo for TODO/DOING style - :preferred-workflow :now - - ;; Exclude directories/files. - ;; This is _only_ for file graphs. - ;; Example usage: - ;; :hidden ["/archived" "/test.md" "../assets/archived"] - :hidden [] - - ;; Define the default journal page template. - ;; Enter the template name between the quotes. - ;; This is _only_ for file graphs. - :default-templates - {:journals ""} - - ;; Set a custom date format for the journal page title. - ;; This is _only_ for file graphs. - ;; Default value: "MMM do, yyyy" - ;; e.g., "Jan 19th, 2038" - ;; Example usage e.g., "Tue 19th, Jan 2038" - ;; :journal/page-title-format "EEE do, MMM yyyy" - - ;; Specify the journal filename format using a valid date format string. - ;; !Warning: - ;; 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" - - ;; Set the default location for storing notes. - ;; This is _only_ for file graphs. - ;; Default value: "pages" - ;; :pages-directory "pages" - - ;; Set the default location for storing journals. - ;; This is _only_ for file graphs. - ;; Default value: "journals" - ;; :journals-directory "journals" - - ;; Set the default location for storing whiteboards. - ;; This is _only_ for file graphs. - ;; Default value: "whiteboards" - ;; :whiteboards-directory "whiteboards" - - ;; Enabling this option converts - ;; [[Grant Ideas]] to [[file:./grant_ideas.org][Grant Ideas]] for org-mode. - ;; For more information, visit https://github.com/logseq/logseq/issues/672 - ;; This is _only_ for file graphs. - ;; :org-mode/insert-file-link? false - -;; Favorites to list on the left sidebar - ;; This is _only_ for file graphs. - :favorites [] - - ;; Set flashcards interval. - ;; This is _only_ for file graphs. - ;; Expected value: - ;; - Float between 0 and 1 - ;; higher values result in faster changes to the next review interval. - ;; Default value: 0.5 - ;; :srs/learning-fraction 0.5 - - ;; Set the initial interval after the first successful review of a card. - ;; This is _only_ for file graphs. - ;; Default value: 4 - ;; :srs/initial-interval 4 - - ;; Hide specific block properties. - ;; This is _only_ for file graphs. - ;; Example usage: - ;; :block-hidden-properties #{:public :icon} - - ;; Create a page for all properties. - ;; This is _only_ for file graphs. - ;; Default value: true - :property-pages/enabled? true - - ;; Properties to exclude from having property pages - ;; This is _only_ for file graphs. - ;; Example usage: - ;; :property-pages/excludelist #{:duration :author} - - ;; By default, property value separated by commas will not be treated as - ;; page references. You can add properties to enable it. - ;; This is _only_ for file graphs. - ;; Example usage: - ;; :property/separated-by-commas #{:alias :tags} - - ;; Properties that are ignored when parsing property values for references - ;; This is _only_ for file graphs. - ;; Example usage: - ;; :ignored-page-references-keywords #{:author :website} - - ;; logbook configuration. - ;; This is _only_ for file graphs. - ;; :logbook/settings - ;; {:with-second-support? false ;limit logbook to minutes, seconds will be eliminated - ;; :enabled-in-all-blocks true ;display logbook in all blocks after timetracking - ;; :enabled-in-timestamped-blocks false ;don't display logbook at all - ;; } - - ;; Configure the escaping method for special characters in page titles. - ;; This is _only_ for file graphs. - ;; Warning: - ;; This is a dangerous operation. To modify the setting, - ;; you'll need to manually rename all affected files and - ;; re-index them on all clients after synchronization. - ;; Incorrect handling may result in messy page titles. - ;; Available options: - ;; - :triple-lowbar (default) - ;; ;use triple underscore `___` for slash `/` in page title - ;; ;use Percent-encoding for other invalid characters - :file/name-format :triple-lowbar - ;; == END OF FILE GRAPH CONFIG == - ;; Hide empty block properties ;; This is _only_ for DB graphs. ;; Default value: false diff --git a/deps/common/src/logseq/common/config.cljs b/deps/common/src/logseq/common/config.cljs index bcc005a77a..f96758b9a5 100644 --- a/deps/common/src/logseq/common/config.cljs +++ b/deps/common/src/logseq/common/config.cljs @@ -67,19 +67,11 @@ s)) (defonce default-draw-directory "draws") -;; TODO read configurable value? -(defonce default-whiteboards-directory "whiteboards") (defn draw? [path] (string/starts-with? path default-draw-directory)) -(defn whiteboard? - [path] - (and path - (string/includes? path (str default-whiteboards-directory "/")) - (string/ends-with? path ".edn"))) - ;; TODO: rename (defonce mldoc-support-formats #{:org :markdown :md}) @@ -97,21 +89,6 @@ [] #{:gif :svg :jpeg :ico :png :jpg :bmp :webp}) -(defn get-date-formatter - [config] - (or - (:journal/page-title-format config) - ;; for compatibility - (:date-formatter config) - "MMM do, yyyy")) - -(defn get-preferred-format - [config] - (or - (when-let [fmt (:preferred-format config)] - (keyword (string/lower-case (name fmt)))) - :markdown)) - (defn get-block-pattern [format] (let [format' (keyword format)] @@ -121,11 +98,6 @@ "-"))) -(defn create-config-for-db-graph - "Given a new config.edn file string, creates a config.edn for use with only DB graphs" - [config] - (string/replace config #"(?m)[\s]*;; == FILE GRAPH CONFIG ==(?:.|\n)*?;; == END OF FILE GRAPH CONFIG ==\n?" "")) - (def file-only-config "File only config keys that are deprecated in DB graphs along with descriptions for their deprecation." diff --git a/deps/common/src/logseq/common/date.cljs b/deps/common/src/logseq/common/date.cljs index ce7e769504..d495d82553 100644 --- a/deps/common/src/logseq/common/date.cljs +++ b/deps/common/src/logseq/common/date.cljs @@ -5,8 +5,6 @@ [logseq.common.util :as common-util] [clojure.string :as string])) -(def default-journal-filename-formatter "yyyy_MM_dd") - (defonce built-in-journal-title-formatters (list "do MMM yyyy" @@ -79,12 +77,4 @@ (defn ^:api valid-journal-title-with-slash? [title] - (some #(valid-journal-title? title %) slash-journal-title-formatters)) - -(defn ^:api date->file-name - "Date object to filename format" - [date journal-filename-formatter] - (let [formatter (if journal-filename-formatter - (tf/formatter journal-filename-formatter) - (tf/formatter default-journal-filename-formatter))] - (tf/unparse formatter date))) + (some #(valid-journal-title? title %) slash-journal-title-formatters)) \ No newline at end of file diff --git a/deps/common/test/logseq/common/config_test.cljc b/deps/common/test/logseq/common/config_test.cljc index 01e59aca63..11a3de8f37 100644 --- a/deps/common/test/logseq/common/config_test.cljc +++ b/deps/common/test/logseq/common/config_test.cljc @@ -1,9 +1,5 @@ (ns logseq.common.config-test - (:require ["fs" :as fs] - ["path" :as node-path] - #?(:org.babashka/nbb [nbb.classpath :as cp]) - [cljs.test :refer [deftest is]] - [clojure.string :as string] + (:require [cljs.test :refer [deftest is]] [logseq.common.config :as common-config])) (deftest remove-hidden-files @@ -23,23 +19,4 @@ (map #(str "/" %) files) {:hidden ["script" "/dev"]} identity)) - "Removes hidden files if they start with '/'"))) - -(defn find-on-classpath [classpath rel-path] - (some (fn [dir] - (let [f (node-path/join dir rel-path)] - (when (fs/existsSync f) f))) - (string/split classpath #":"))) - -#?(:org.babashka/nbb - (deftest create-config-for-db-graph - (let [original-config (some-> (find-on-classpath (cp/get-classpath) "templates/config.edn") fs/readFileSync str) - _ (assert original-config "config.edn must not be blank") - migrated-config (common-config/create-config-for-db-graph original-config) - forbidden-kws-regex (re-pattern (str (string/join "|" (keys common-config/file-only-config))))] - ;; (println migrated-config) - (is (not (string/includes? migrated-config "== FILE ONLY CONFIG")) - "No longer includes file config header") - (assert (re-find forbidden-kws-regex original-config) "File config keys present in original config") - (is (not (re-find forbidden-kws-regex migrated-config)) - "File config keys no longer present in migrated config")))) \ No newline at end of file + "Removes hidden files if they start with '/'"))) \ No newline at end of file diff --git a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs index b032c38fbf..c0c655bef4 100644 --- a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs @@ -314,11 +314,25 @@ (dissoc :block/priority))) block)) +(defn- get-date-formatter + [config] + (or + (:journal/page-title-format config) + ;; for compatibility + (:date-formatter config) + "MMM do, yyyy")) + +(defn- config-whiteboard? + [path] + (and path + (string/includes? path (str "whiteboards" "/")) + (string/ends-with? path ".edn"))) + (defn- find-or-create-deadline-scheduled-value "Given a :block/scheduled or :block/deadline value, creates the datetime property value and any optional journal tx associated with that value" [date-int page-names-to-uuids user-config] - (let [title (date-time-util/int->journal-title date-int (common-config/get-date-formatter user-config)) + (let [title (date-time-util/int->journal-title date-int (get-date-formatter user-config)) existing-journal-page (some->> title common-util/page-name-sanity-lc (get @page-names-to-uuids) @@ -1745,7 +1759,7 @@ (map #(dissoc % :block.temp/original-page-name) pages))) (update :blocks fix-extracted-block-tags-and-refs)) - (common-config/whiteboard? file) + (config-whiteboard? file) (-> (extract/extract-whiteboard-edn file content extract-options') (update :pages (fn [pages] (->> pages @@ -2102,7 +2116,7 @@ (defn build-doc-options "Builds options for use with export-doc-files and assets" [config options] - (-> {:extract-options {:date-formatter (common-config/get-date-formatter config) + (-> {:extract-options {:date-formatter (get-date-formatter config) ;; Remove config keys that break importing :user-config (dissoc config :property-pages/excludelist :property-pages/enabled?) :filename-format (or (:file/name-format config) :legacy) diff --git a/deps/outliner/src/logseq/outliner/cli.cljs b/deps/outliner/src/logseq/outliner/cli.cljs index c1dab02f75..75a3ef9d35 100644 --- a/deps/outliner/src/logseq/outliner/cli.cljs +++ b/deps/outliner/src/logseq/outliner/cli.cljs @@ -5,7 +5,6 @@ ["path" :as node-path] [borkdude.rewrite-edn :as rewrite] [clojure.string :as string] - [logseq.common.config :as common-config] [logseq.db :as ldb] [logseq.db.common.sqlite-cli :as sqlite-cli] [logseq.db.sqlite.build :as sqlite-build] @@ -43,8 +42,6 @@ (cond-> (or (some-> (find-on-classpath classpath "templates/config.edn") fs/readFileSync str) (do (println "Setting graph's config to empty since no templates/config.edn was found.") "{}")) - true - (common-config/create-config-for-db-graph) additional-config (pretty-print-merge additional-config)) git-sha (get-git-sha)] diff --git a/src/main/frontend/common/file/util.cljs b/src/main/frontend/common/file/util.cljs deleted file mode 100644 index cb419018a5..0000000000 --- a/src/main/frontend/common/file/util.cljs +++ /dev/null @@ -1,79 +0,0 @@ -(ns frontend.common.file.util - "File name fns. Used by worker and frontend namespaces" - (:require [clojure.string :as string] - [logseq.common.util :as common-util] - [logseq.db :as ldb])) - -;; Update repo/invalid-graph-name-warning if characters change -(def multiplatform-reserved-chars ":\\*\\?\"<>|\\#\\\\") - -(def reserved-chars-pattern - (re-pattern (str "[" multiplatform-reserved-chars "]+"))) - -(defn- encode-url-lowbar - [input] - (string/replace input "_" "%5F")) - -(defn- encode-url-percent - [input] - (string/replace input "%" "%25")) - -(defn- escape-namespace-slashes-and-multilowbars - "Encode slashes / as triple lowbars ___ - Don't encode _ in most cases, except causing ambiguation" - [string] - (-> string - ;; The ambiguation is caused by the unbounded _ (possible continuation of `_`s) - (string/replace "___" encode-url-lowbar) - (string/replace "_/" encode-url-lowbar) - (string/replace "/_" encode-url-lowbar) - ;; After ambiguaous _ encoded, encode the slash - (string/replace "/" "___"))) - -(def windows-reserved-filebodies - (set '("CON" "PRN" "AUX" "NUL" "COM1" "COM2" "COM3" "COM4" "COM5" "COM6" - "COM7" "COM8" "COM9" "LPT1" "LPT2" "LPT3" "LPT4" "LPT5" "LPT6" "LPT7" - "LPT8" "LPT9"))) - -(defn- escape-windows-reserved-filebodies - "Encode reserved file names in Windows" - [file-body] - (str file-body (when (or (contains? windows-reserved-filebodies file-body) - (string/ends-with? file-body ".")) - "/"))) ;; "___" would not break the title, but follow the Windows ruling - -(defn- url-encode-file-name - [file-name] - (-> file-name - js/encodeURIComponent - (string/replace "*" "%2A") ;; extra token that not involved in URI encoding - )) - -(defn- tri-lb-file-name-sanity - "Sanitize page-name for file name (strict), for file name in file writing. - Use triple lowbar as namespace separator" - [title] - (some-> title - common-util/page-name-sanity ;; we want to preserve the case sensitive nature of most file systems, don't lowercase - (string/replace common-util/url-encoded-pattern encode-url-percent) ;; pre-encode % in title on demand - (string/replace reserved-chars-pattern url-encode-file-name) - (escape-windows-reserved-filebodies) ;; do this before the lowbar encoding to avoid ambiguity - (escape-namespace-slashes-and-multilowbars))) - -;; Register sanitization / parsing fns in: -;; logseq.common.util (parsing only) -;; frontend.util.fs (sanitization only) -(defn file-name-sanity - [title] - (when (string? title) - (tri-lb-file-name-sanity title))) - -(defn include-reserved-chars? - "Includes reserved characters that would broken FS" - [s] - (common-util/safe-re-find reserved-chars-pattern s)) - -(defn post-message - [type data & {:keys [port]}] - (when-let [worker (or port js/self)] - (.postMessage worker (ldb/write-transit-str [type data])))) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index a2f10a2488..90d3badd26 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -210,7 +210,7 @@ (set-matched-pages! result)))) (rum/defc page-search-aux - [id format embed? db-tag? q current-pos input pos] + [id format embed? db-tag? q input pos] (let [q (string/trim q) [matched-pages set-matched-pages!] (rum/use-state nil) search-f #(search-pages q db-tag? set-matched-pages!)] @@ -234,7 +234,7 @@ matched-pages' {:on-chosen (page-on-chosen-handler embed? input id q pos format) :on-enter (fn [] - (page-handler/page-not-exists-handler input id q current-pos)) + (page-handler/page-not-exists-handler input)) :item-render (fn [block _chosen?] (node-render block q {:db-tag? db-tag?})) :empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 (if db-tag? @@ -273,7 +273,7 @@ (when (> (count edit-content) current-pos) (common-util/safe-subs edit-content pos current-pos)) "")] - (page-search-aux id format embed? db-tag? q current-pos input pos))))) + (page-search-aux id format embed? db-tag? q input pos))))) (defn- search-blocks! [state result] diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs index 4088acf8f9..ae65694e43 100644 --- a/src/main/frontend/config.cljs +++ b/src/main/frontend/config.cljs @@ -281,17 +281,6 @@ (+ 3 (count label))] ["" 0])) -(defonce default-journals-directory "journals") -(defonce default-pages-directory "pages") - -(defn get-pages-directory - [] - (or (state/get-pages-directory) default-pages-directory)) - -(defn get-journals-directory - [] - (or (state/get-journals-directory) default-journals-directory)) - (defonce demo-repo "Demo") (defn demo-graph? diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index d2ee3c1f2a..8eb8fe06dd 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -117,8 +117,6 @@ [journal-title] (journal-title-> journal-title #(tc/to-long %))) -(def default-journal-filename-formatter common-date/default-journal-filename-formatter) - (defn int->local-time-2 [n] (tf/unparse diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 38431add73..3d24c24767 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -127,12 +127,8 @@ :validate-db-options (:dev/validate-db-options (state/get-config)) :importing? (:graph/importing @state/state) :date-formatter (state/get-date-formatter) - :journal-file-name-format (or (state/get-journal-file-name-format) - date/default-journal-filename-formatter) :export-bullet-indentation (state/get-export-bullet-indentation) - :preferred-format (state/get-preferred-format) - :journals-directory (config/get-journals-directory) - :pages-directory (config/get-pages-directory)}] + :preferred-format (state/get-preferred-format)}] (state/page-ref q) - new-value (string/replace value - old-page-ref - page-ref-text)] - (state/set-edit-content! id new-value) - (let [new-pos (+ current-pos - (- (count page-ref-text) - (count old-page-ref)) - 2)] - (cursor/move-cursor-to input new-pos))) - (let [current-selected (util/get-selected-text)] - (cursor/move-cursor-forward input (+ 2 (count current-selected)))))) + (let [current-selected (util/get-selected-text)] + (cursor/move-cursor-forward input (+ 2 (count current-selected))))) (defn- tag-on-chosen-handler [input id pos format current-pos edit-content q] diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 707c7d60eb..04191bcb67 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -20,7 +20,6 @@ [frontend.undo-redo :as undo-redo] [frontend.util :as util] [frontend.util.text :as text-util] - [logseq.common.config :as common-config] [logseq.db.frontend.schema :as db-schema] [promesa.core :as p])) @@ -135,7 +134,7 @@ (defn- create-db [full-graph-name {:keys [file-graph-import?]}] (-> - (p/let [config (common-config/create-config-for-db-graph config/config-default-content) + (p/let [config config/config-default-content _ (persist-db/ {:config config :graph-git-sha config/revision} diff --git a/src/main/frontend/mobile/intent.cljs b/src/main/frontend/mobile/intent.cljs index 42a74bf6f4..81d854708d 100644 --- a/src/main/frontend/mobile/intent.cljs +++ b/src/main/frontend/mobile/intent.cljs @@ -16,11 +16,8 @@ [frontend.mobile.util :as mobile-util] [frontend.state :as state] [frontend.util :as util] - [frontend.util.fs :as fs-util] - [frontend.util.ref :as ref] [goog.string :as gstring] [lambdaisland.glogi :as log] - [logseq.common.config :as common-config] [logseq.common.util :as common-util] [promesa.core :as p])) @@ -122,33 +119,6 @@ (state/get-current-repo) [file] {})] (first result))) -(defn- embed-text-file - "Store external content with url into Logseq repo" - [url title] - (p/let [time (date/get-current-time) - date-ref-name (date/today) - title (some-> (or title (node-path/basename url)) - common-util/safe-decode-uri-component - util/node-path.name - ;; make the title more user friendly - common-util/page-name-sanity) - path (node-path/join (config/get-repo-dir (state/get-current-repo)) - (config/get-pages-directory) - (str (js/encodeURI (fs-util/file-name-sanity title :markdown)) (node-path/extname url))) - _ (p/catch - (.copy Filesystem (clj->js {:from (normalize-native-file-path url) :to path})) - (fn [error] - (log/error :copy-file-error {:error error}))) - url (ref/->page-ref title) - template (get-in (state/get-config) - [:quick-capture-templates :text] - "**{time}** [[quick capture]]: {url}")] - (-> template - (string/replace "{time}" time) - (string/replace "{date}" date-ref-name) - (string/replace "{text}" "") - (string/replace "{url}" (or url ""))))) - (defn- handle-received-media [result] (p/let [{:keys [url]} result page (or (state/get-current-page) (string/lower-case (date/journal-name))) @@ -159,14 +129,11 @@ (notification/show! "Failed to import the shared media. Please try again." :error false)))))) (defn- handle-received-application [result] - (p/let [{:keys [title url type]} result + (p/let [{:keys [url type]} result page (or (state/get-current-page) (string/lower-case (date/journal-name))) format (db/get-page-format page) application-type (last (string/split type "/")) content (cond - (common-config/mldoc-support? application-type) - (embed-text-file url title) - (contains? (set/union config/doc-formats config/media-formats) (keyword application-type)) (do diff --git a/src/main/frontend/persist_db/browser.cljs b/src/main/frontend/persist_db/browser.cljs index 79ec158b23..1f9ef82ad0 100644 --- a/src/main/frontend/persist_db/browser.cljs +++ b/src/main/frontend/persist_db/browser.cljs @@ -7,7 +7,6 @@ [frontend.common.missionary :as c.m] [frontend.common.thread-api :as thread-api] [frontend.config :as config] - [frontend.date :as date] [frontend.db :as db] [frontend.db.transact :as db-transact] [frontend.handler.notification :as notification] @@ -83,12 +82,8 @@ :validate-db-options (:dev/validate-db-options (state/get-config)) :importing? (:graph/importing @state/state) :date-formatter (state/get-date-formatter) - :journal-file-name-format (or (state/get-journal-file-name-format) - date/default-journal-filename-formatter) :export-bullet-indentation (state/get-export-bullet-indentation) - :preferred-format (state/get-preferred-format) - :journals-directory (config/get-journals-directory) - :pages-directory (config/get-pages-directory)}] + :preferred-format (state/get-preferred-format)}] (state/|\\#\\\\") + +(def reserved-chars-pattern + (re-pattern (str "[" multiplatform-reserved-chars "]+"))) + +(defn include-reserved-chars? + "Includes reserved characters that would broken FS" + [s] + (common-util/safe-re-find reserved-chars-pattern s)) \ No newline at end of file diff --git a/src/main/frontend/worker/state.cljs b/src/main/frontend/worker/state.cljs index 4ce1e65181..9b2ceeb9b1 100644 --- a/src/main/frontend/worker/state.cljs +++ b/src/main/frontend/worker/state.cljs @@ -1,7 +1,6 @@ (ns frontend.worker.state "State hub for worker" - (:require [logseq.common.config :as common-config] - [logseq.common.util :as common-util])) + (:require [logseq.common.util :as common-util])) (defonce *main-thread (atom nil)) (defonce *infer-worker (atom nil)) @@ -96,10 +95,6 @@ (fn [c] (merge c context)))) -(defn get-config - [repo] - (get-in @*state [:config repo])) - (defn get-current-repo [] (:git/current-repo @*state)) @@ -109,9 +104,10 @@ (swap! *state (fn [old-state] (merge old-state new-state)))) +;; TODO: Move or remove as this is no longer stateful (defn get-date-formatter - [repo] - (common-config/get-date-formatter (get-config repo))) + [_repo] + "MMM do, yyyy") (defn set-rtc-downloading-graph! [value] diff --git a/src/main/frontend/worker_common/util.cljc b/src/main/frontend/worker_common/util.cljc index 24f74fe171..c91d9054d8 100644 --- a/src/main/frontend/worker_common/util.cljc +++ b/src/main/frontend/worker_common/util.cljc @@ -7,7 +7,7 @@ [goog.crypt.Hmac] [goog.crypt.Sha256] [logseq.db.common.sqlite :as common-sqlite] - [frontend.common.file.util :as wfu]))) + [logseq.db :as ldb]))) ;; Copied from https://github.com/tonsky/datascript-todo #?(:clj @@ -26,7 +26,10 @@ #?(:cljs (do - (def post-message wfu/post-message) + (defn post-message + [type data & {:keys [port]}] + (when-let [worker (or port js/self)] + (.postMessage worker (ldb/write-transit-str [type data])))) (defn get-pool-name [graph-name] diff --git a/src/test/frontend/db/name_sanity_test.cljs b/src/test/frontend/db/name_sanity_test.cljs deleted file mode 100644 index a2ad51d47a..0000000000 --- a/src/test/frontend/db/name_sanity_test.cljs +++ /dev/null @@ -1,46 +0,0 @@ -(ns frontend.db.name-sanity-test - (:require [cljs.test :refer [deftest testing is]] - [clojure.string :as string] - [frontend.common.file.util :as wfu] - [frontend.util.fs :as fs-util] - [logseq.graph-parser.extract :as extract])) - -(defn- test-page-name - "Check if page name can be preserved after escaping" - [page-name] - (testing (str "Test sanitization page-name: " page-name) - (let [file-name (#'wfu/tri-lb-file-name-sanity page-name) - page-name' (#'extract/tri-lb-title-parsing file-name) - url-single (js/encodeURIComponent file-name) - url-double (js/encodeURIComponent url-single) - file-name' (js/decodeURIComponent url-single) - file-name'' (js/decodeURIComponent (js/decodeURIComponent url-double))] - (is (= page-name page-name')) - (is (not (fs-util/include-reserved-chars? file-name))) - (is (not (contains? fs-util/windows-reserved-filebodies file-name))) - (is (not (string/ends-with? file-name "."))) - (is (= file-name' file-name)) - (is (= file-name'' file-name))))) - -(deftest page-name-sanitization-tests - (test-page-name "Some.Content!") - (test-page-name "More _/_ Con tents") - (test-page-name "More _________/________ Con tents") - (test-page-name "More _________/___-_-_-_---___----__/_ Con tents") - (test-page-name "Cont./__cont_ cont/ lsdksdf") - (test-page-name "Cont.?/#__cont_ cont%/_ lsdksdf") - (test-page-name "Cont.?__byte/#__cont_ cont%/_ lsdksdf") - (test-page-name "__ont.?__byte/#__cont_ cont%/_ lsdksdf") - (test-page-name "______ont.?__byte/#__cont_ cont%/_ lsdksdf") - (test-page-name "__ont.?__byte/#__cont_ cont%/_ lsdksdf__") - (test-page-name "+*++***+++__byte/#__cont_ cont%/_ lsdksdf__") - (test-page-name "+*++_.x2A_.x2A***+++__byte/#__cont_ cont%/_ lsdksdf__") - (test-page-name "__ont.?__byte/#__0xbbcont_ cont%/_ lsdksdf__") - (test-page-name "__ont.?__byte/#_&ont_ cont%/_ lsdksdf__") - (test-page-name "__ont.?__byte_/#_&ont_ cont%/_ lsdksdf__") - (test-page-name "dsa&;l dsalfjk jkl") - (test-page-name "dsa&;l dsalfjk jkl.") - (test-page-name "hls__&;l dsalfjk jkl.") - (test-page-name "CON.") - (test-page-name ".NET.") - (mapv test-page-name fs-util/windows-reserved-filebodies)) diff --git a/src/test/frontend/handler/common/config_edn_test.cljs b/src/test/frontend/handler/common/config_edn_test.cljs index b38181b29d..09a7b19e0d 100644 --- a/src/test/frontend/handler/common/config_edn_test.cljs +++ b/src/test/frontend/handler/common/config_edn_test.cljs @@ -28,12 +28,12 @@ (testing "Valid cases" (is (= true (config-edn-common-handler/validate-config-edn - "config.edn" "{:preferred-workflow :todo}" global-config-schema/Config-edn)) + "config.edn" "{:macros {}}" global-config-schema/Config-edn)) "global config.edn") (is (= true (config-edn-common-handler/validate-config-edn - "config.edn" "{:preferred-workflow :todo}" repo-config-schema/Config-edn)) + "config.edn" "{:macros {}}" repo-config-schema/Config-edn)) "repo config.edn")) (doseq [[file-type schema] {"global config.edn" global-config-schema/Config-edn @@ -45,7 +45,7 @@ (str "Not a map for " file-type)) (is (string/includes? - (validation-config-error-for "{:preferred-workflow :todo" schema) + (validation-config-error-for "{:macros" schema) "Failed to read") (str "Invalid edn for " file-type)) diff --git a/src/test/frontend/state_test.cljs b/src/test/frontend/state_test.cljs index 92640392ad..5b8cf7a7f8 100644 --- a/src/test/frontend/state_test.cljs +++ b/src/test/frontend/state_test.cljs @@ -5,10 +5,8 @@ (deftest merge-configs (let [global-config {:shortcuts {:ui/toggle-theme "t z"} - :hidden [] :ui/enable-tooltip? true} - local-config {:hidden ["foo" "bar"] - :ui/enable-tooltip? false}] + local-config {:ui/enable-tooltip? false}] (is (= local-config (dissoc (state/merge-configs global-config local-config) :shortcuts)) "Later config overrides all non-map values") diff --git a/src/test/frontend/worker/rtc/rtc_fns_test.cljs b/src/test/frontend/worker/rtc/rtc_fns_test.cljs index 2ce1331466..b9a7af24ad 100644 --- a/src/test/frontend/worker/rtc/rtc_fns_test.cljs +++ b/src/test/frontend/worker/rtc/rtc_fns_test.cljs @@ -404,7 +404,7 @@ result: (deftest same-name-two-pages-merge-test (let [repo (state/get-current-repo) conn (conn/get-db repo false) - date-formatter (common-config/get-date-formatter (worker-state/get-config repo)) + date-formatter (worker-state/get-date-formatter) opts {:persist-op? false :transact-opts {:repo repo :conn conn}}