|
|
@@ -9,22 +9,22 @@
|
|
|
[clojure.walk :as walk]
|
|
|
[datascript.core :as d]
|
|
|
[logseq.graph-parser.text :as text]
|
|
|
- [logseq.graph-parser.util :as gp-util]
|
|
|
+ [logseq.common.util :as common-util]
|
|
|
[logseq.graph-parser.mldoc :as gp-mldoc]
|
|
|
[logseq.graph-parser.block :as gp-block]
|
|
|
[logseq.graph-parser.property :as gp-property]
|
|
|
- [logseq.graph-parser.config :as gp-config]
|
|
|
- #?(:org.babashka/nbb [logseq.graph-parser.log :as log]
|
|
|
+ [logseq.common.config :as common-config]
|
|
|
+ #?(:org.babashka/nbb [logseq.common.log :as log]
|
|
|
:default [lambdaisland.glogi :as log])
|
|
|
[logseq.graph-parser.whiteboard :as gp-whiteboard]))
|
|
|
|
|
|
(defn- filepath->page-name
|
|
|
[filepath]
|
|
|
(when-let [file-name (last (string/split filepath #"/"))]
|
|
|
- (let [result (first (gp-util/split-last "." file-name))
|
|
|
- ext (string/lower-case (gp-util/get-file-ext filepath))]
|
|
|
- (if (or (gp-config/mldoc-support? ext) (= "edn" ext))
|
|
|
- (gp-util/safe-decode-uri-component (string/replace result "." "/"))
|
|
|
+ (let [result (first (common-util/split-last "." file-name))
|
|
|
+ ext (string/lower-case (common-util/get-file-ext filepath))]
|
|
|
+ (if (or (common-config/mldoc-support? ext) (= "edn" ext))
|
|
|
+ (common-util/safe-decode-uri-component (string/replace result "." "/"))
|
|
|
result))))
|
|
|
|
|
|
(defn- get-page-name
|
|
|
@@ -54,9 +54,9 @@
|
|
|
(and first-block
|
|
|
(string? title)
|
|
|
title))
|
|
|
- file-name (when-let [result (gp-util/path->file-body file)]
|
|
|
- (if (gp-config/mldoc-support? (gp-util/get-file-ext file))
|
|
|
- (gp-util/title-parsing result filename-format)
|
|
|
+ file-name (when-let [result (common-util/path->file-body file)]
|
|
|
+ (if (common-config/mldoc-support? (common-util/get-file-ext file))
|
|
|
+ (common-util/title-parsing result filename-format)
|
|
|
result))]
|
|
|
(or property-name
|
|
|
file-name
|
|
|
@@ -67,12 +67,12 @@
|
|
|
(let [alias (:alias properties)
|
|
|
alias' (if (coll? alias) alias [(str alias)])
|
|
|
aliases (and alias'
|
|
|
- (seq (remove #(or (= page-name (gp-util/page-name-sanity-lc %))
|
|
|
+ (seq (remove #(or (= page-name (common-util/page-name-sanity-lc %))
|
|
|
(string/blank? %)) ;; disable blank alias
|
|
|
alias')))
|
|
|
aliases' (keep
|
|
|
(fn [alias]
|
|
|
- (let [page-name (gp-util/page-name-sanity-lc alias)
|
|
|
+ (let [page-name (common-util/page-name-sanity-lc alias)
|
|
|
aliases (distinct
|
|
|
(conj
|
|
|
(remove #{alias} aliases)
|
|
|
@@ -80,7 +80,7 @@
|
|
|
aliases (when (seq aliases)
|
|
|
(map
|
|
|
(fn [alias]
|
|
|
- {:block/name (gp-util/page-name-sanity-lc alias)})
|
|
|
+ {:block/name (common-util/page-name-sanity-lc alias)})
|
|
|
aliases))]
|
|
|
(if (seq aliases)
|
|
|
{:block/name page-name
|
|
|
@@ -97,7 +97,7 @@
|
|
|
(assoc :block/tags (let [tags (:tags properties)
|
|
|
tags (if (coll? tags) tags [(str tags)])
|
|
|
tags (remove string/blank? tags)]
|
|
|
- (map (fn [tag] {:block/name (gp-util/page-name-sanity-lc tag)
|
|
|
+ (map (fn [tag] {:block/name (common-util/page-name-sanity-lc tag)
|
|
|
:block/original-name tag})
|
|
|
tags))))]
|
|
|
(update result :block/properties #(apply dissoc % gp-property/editable-linkable-built-in-properties))))
|
|
|
@@ -111,11 +111,11 @@
|
|
|
invalid-properties (set (->> (map (comp name first) *invalid-properties)
|
|
|
(concat invalid-properties)))
|
|
|
page-m (->
|
|
|
- (gp-util/remove-nils-non-nested
|
|
|
+ (common-util/remove-nils-non-nested
|
|
|
(assoc
|
|
|
(gp-block/page-name->map page false db true date-formatter
|
|
|
:from-page from-page)
|
|
|
- :block/file {:file/path (gp-util/path-normalize file)}))
|
|
|
+ :block/file {:file/path (common-util/path-normalize file)}))
|
|
|
(extract-page-alias-and-tags page page-name properties))]
|
|
|
(cond->
|
|
|
page-m
|
|
|
@@ -193,7 +193,7 @@
|
|
|
page-map (build-page-map properties invalid-properties properties-text-values file page page-name (assoc options' :from-page page))
|
|
|
namespace-pages (let [page (:block/original-name page-map)]
|
|
|
(when (text/namespace-page? page)
|
|
|
- (->> (gp-util/split-namespace-pages page)
|
|
|
+ (->> (common-util/split-namespace-pages page)
|
|
|
(map (fn [page]
|
|
|
(-> (gp-block/page-name->map page true db true date-formatter)
|
|
|
(assoc :block/format format)))))))
|
|
|
@@ -204,7 +204,7 @@
|
|
|
;; remove block references
|
|
|
(remove vector?)
|
|
|
(remove nil?))
|
|
|
- pages (gp-util/distinct-by :block/name pages)
|
|
|
+ pages (common-util/distinct-by :block/name pages)
|
|
|
pages (remove nil? pages)
|
|
|
pages (map (fn [page] (assoc page :block/uuid (d/squuid))) pages)
|
|
|
blocks (->> (remove nil? blocks)
|
|
|
@@ -218,7 +218,7 @@
|
|
|
[file-path content {:keys [user-config verbose] :or {verbose true} :as options}]
|
|
|
(if (string/blank? content)
|
|
|
[]
|
|
|
- (let [format (gp-util/get-format file-path)
|
|
|
+ (let [format (common-util/get-format file-path)
|
|
|
_ (when verbose (println "Parsing start: " file-path))
|
|
|
ast (gp-mldoc/->edn content (gp-mldoc/default-config format
|
|
|
;; {:parse_outline_only? true}
|
|
|
@@ -252,24 +252,24 @@
|
|
|
- blocks will be adapted to tldraw shapes. All blocks's parent is the given page."
|
|
|
[file content {:keys [verbose] :or {verbose true}}]
|
|
|
(let [_ (when verbose (println "Parsing start: " file))
|
|
|
- {:keys [pages blocks]} (gp-util/safe-read-string content)
|
|
|
+ {:keys [pages blocks]} (common-util/safe-read-string content)
|
|
|
blocks (map
|
|
|
(fn [block]
|
|
|
(-> block
|
|
|
- (gp-util/dissoc-in [:block/parent :block/name])
|
|
|
- (gp-util/dissoc-in [:block/left :block/name])))
|
|
|
+ (common-util/dissoc-in [:block/parent :block/name])
|
|
|
+ (common-util/dissoc-in [:block/left :block/name])))
|
|
|
blocks)
|
|
|
serialized-page (first pages)
|
|
|
;; whiteboard edn file should normally have valid :block/original-name, :block/name, :block/uuid
|
|
|
page-name (-> (or (:block/name serialized-page)
|
|
|
(filepath->page-name file))
|
|
|
- (gp-util/page-name-sanity-lc))
|
|
|
+ (common-util/page-name-sanity-lc))
|
|
|
original-name (or (:block/original-name serialized-page)
|
|
|
page-name)
|
|
|
page-block (merge {:block/name page-name
|
|
|
:block/original-name original-name
|
|
|
:block/type "whiteboard"
|
|
|
- :block/file {:file/path (gp-util/path-normalize file)}}
|
|
|
+ :block/file {:file/path (common-util/path-normalize file)}}
|
|
|
serialized-page)
|
|
|
page-block (gp-whiteboard/migrate-page-block page-block)
|
|
|
blocks (->> blocks
|
|
|
@@ -281,7 +281,7 @@
|
|
|
|
|
|
(defn- with-block-uuid
|
|
|
[pages]
|
|
|
- (->> (gp-util/distinct-by :block/name pages)
|
|
|
+ (->> (common-util/distinct-by :block/name pages)
|
|
|
(map (fn [page]
|
|
|
(if (:block/uuid page)
|
|
|
page
|