|
1208 | 1208 |
|
1209 | 1209 | (defn- <handle-assets-in-block |
1210 | 1210 | "If a block contains assets, creates them as #Asset nodes in the Asset page and references them in the block." |
1211 | | - [config block {:keys [asset-links]} {:keys [assets ignored-assets pdf-annotation-pages]} {:keys [notify-user <get-file-stat] :as opts}] |
| 1211 | + [block {:keys [asset-links]} {:keys [assets ignored-assets pdf-annotation-pages]} {:keys [notify-user <get-file-stat user-config] :as opts}] |
1212 | 1212 | (if (seq asset-links) |
1213 | 1213 | (p/let [asset-maps* (p/all (map |
1214 | 1214 | (fn [asset-link] |
1215 | 1215 | (p/let [path* (-> asset-link second :url second) |
1216 | 1216 | {:keys [path link base]} (if (map? path*) |
1217 | | - (get-zotero-local-pdf-path config (second asset-link)) |
| 1217 | + (get-zotero-local-pdf-path user-config (second asset-link)) |
1218 | 1218 | {:path path*}) |
1219 | 1219 | asset-name (-> path asset-path->name) |
1220 | 1220 | asset-link-or-name (or link (-> path asset-path->name)) |
|
1313 | 1313 | block)) |
1314 | 1314 |
|
1315 | 1315 | (defn- <build-block-tx |
1316 | | - [db config block* pre-blocks {:keys [page-names-to-uuids] :as per-file-state} {:keys [import-state journal-created-ats] :as options}] |
| 1316 | + [db block* pre-blocks {:keys [page-names-to-uuids] :as per-file-state} |
| 1317 | + {:keys [import-state journal-created-ats user-config] :as options}] |
1317 | 1318 | ;; (prn ::block-in block*) |
1318 | | - (p/let [walked-ast-blocks (walk-ast-blocks config (:block.temp/ast-blocks block*)) |
| 1319 | + (p/let [walked-ast-blocks (walk-ast-blocks user-config (:block.temp/ast-blocks block*)) |
1319 | 1320 | ;; needs to come before update-block-refs to detect new property schemas |
1320 | 1321 | {:keys [block properties-tx]} |
1321 | 1322 | (handle-block-properties block* db page-names-to-uuids (:block/refs block*) walked-ast-blocks options) |
1322 | 1323 | {block-after-built-in-props :block deadline-properties-tx :properties-tx} |
1323 | 1324 | (update-block-deadline-and-scheduled block page-names-to-uuids options) |
1324 | 1325 | {block-after-assets :block :keys [asset-blocks-tx]} |
1325 | | - (<handle-assets-in-block config block-after-built-in-props walked-ast-blocks import-state (select-keys options [:log-fn :notify-user :<get-file-stat])) |
| 1326 | + (<handle-assets-in-block block-after-built-in-props walked-ast-blocks import-state (select-keys options [:log-fn :notify-user :<get-file-stat])) |
1326 | 1327 | ;; :block/page should be [:block/page NAME] |
1327 | 1328 |
|
1328 | 1329 | journal-page-created-at (some-> (:block/page block*) second journal-created-ats) |
|
1811 | 1812 | (swap! (:all-existing-page-uuids import-state) merge (into {} (map (juxt :block/uuid identity) nodes))))) |
1812 | 1813 |
|
1813 | 1814 | (defn- <build-blocks-tx |
1814 | | - [conn config blocks pre-blocks per-file-state tx-options] |
| 1815 | + [conn blocks pre-blocks per-file-state tx-options] |
1815 | 1816 | (p/loop [tx-data [] |
1816 | 1817 | blocks (remove :block/pre-block? blocks)] |
1817 | 1818 | (if-let [block (first blocks)] |
1818 | | - (p/let [block-tx-data (<build-block-tx @conn config block pre-blocks per-file-state |
| 1819 | + (p/let [block-tx-data (<build-block-tx @conn block pre-blocks per-file-state |
1819 | 1820 | tx-options)] |
1820 | 1821 | (p/recur (concat tx-data block-tx-data) (rest blocks))) |
1821 | 1822 | tx-data))) |
|
1831 | 1832 | * :macros - map of macros for use with macro expansion |
1832 | 1833 | * :notify-user - Displays warnings to user without failing the import. Fn receives a map with :msg |
1833 | 1834 | * :log-fn - Logs messages for development. Defaults to prn" |
1834 | | - [conn config file content {:keys [notify-user log-fn] |
1835 | | - :or {notify-user #(println "[WARNING]" (:msg %)) |
1836 | | - log-fn prn} |
1837 | | - :as *options}] |
| 1835 | + [conn file content {:keys [notify-user log-fn] |
| 1836 | + :or {notify-user #(println "[WARNING]" (:msg %)) |
| 1837 | + log-fn prn} |
| 1838 | + :as *options}] |
1838 | 1839 | (p/let [options (assoc *options :notify-user notify-user :log-fn log-fn :file file) |
1839 | 1840 | {:keys [pages blocks]} (extract-pages-and-blocks @conn file content options) |
1840 | 1841 | tx-options (merge (build-tx-options options) |
|
1851 | 1852 | pre-blocks (->> blocks (keep #(when (:block/pre-block? %) (:block/uuid %))) set) |
1852 | 1853 |
|
1853 | 1854 | blocks-tx (let [tx-options' (assoc tx-options :whiteboard? (some? (seq whiteboard-pages)))] |
1854 | | - (<build-blocks-tx conn config blocks pre-blocks per-file-state tx-options')) |
| 1855 | + (<build-blocks-tx conn blocks pre-blocks per-file-state tx-options')) |
1855 | 1856 | {:keys [property-pages-tx property-page-properties-tx] pages-tx' :pages-tx} |
1856 | 1857 | (split-pages-and-properties-tx pages-tx old-properties existing-pages (:import-state options) @(:upstream-properties tx-options)) |
1857 | 1858 | ;; _ (when (seq property-pages-tx) (cljs.pprint/pprint {:property-pages-tx property-pages-tx})) |
|
1898 | 1899 | ;; ======================= |
1899 | 1900 |
|
1900 | 1901 | (defn- export-doc-file |
1901 | | - [{:keys [path idx] :as file} conn config <read-file |
| 1902 | + [{:keys [path idx] :as file} conn <read-file |
1902 | 1903 | {:keys [notify-user set-ui-state <export-file] |
1903 | 1904 | :or {set-ui-state (constantly nil) |
1904 | | - <export-file (fn <export-file [conn config m opts] |
1905 | | - (<add-file-to-db-graph conn config (:file/path m) (:file/content m) opts))} |
| 1905 | + <export-file (fn <export-file [conn m opts] |
| 1906 | + (<add-file-to-db-graph conn (:file/path m) (:file/content m) opts))} |
1906 | 1907 | :as options}] |
1907 | 1908 | ;; (prn :export-doc-file path idx) |
1908 | 1909 | (-> (p/let [_ (set-ui-state [:graph/importing-state :current-idx] (inc idx)) |
1909 | 1910 | _ (set-ui-state [:graph/importing-state :current-page] path) |
1910 | 1911 | content (<read-file file) |
1911 | | - m {:file/path path :file/content content}] |
1912 | | - (<export-file conn config m (dissoc options :set-ui-state :<export-file)) |
| 1912 | + m {:file/path path :file/content content} |
| 1913 | + _ (<export-file conn m (dissoc options :set-ui-state :<export-file))] |
1913 | 1914 | ;; returning val results in smoother ui updates |
1914 | 1915 | m) |
1915 | 1916 | (p/catch (fn [error] |
|
1920 | 1921 | (defn export-doc-files |
1921 | 1922 | "Exports all user created files i.e. under journals/ and pages/. |
1922 | 1923 | Recommended to use build-doc-options and pass that as options" |
1923 | | - [conn config *doc-files <read-file {:keys [notify-user set-ui-state] |
1924 | | - :or {set-ui-state (constantly nil) notify-user prn} |
1925 | | - :as options}] |
| 1924 | + [conn *doc-files <read-file {:keys [notify-user set-ui-state] |
| 1925 | + :or {set-ui-state (constantly nil) notify-user prn} |
| 1926 | + :as options}] |
1926 | 1927 | (set-ui-state [:graph/importing-state :total] (count *doc-files)) |
1927 | 1928 | (let [doc-files (mapv #(assoc %1 :idx %2) |
1928 | 1929 | ;; Sort files to ensure reproducible import behavior |
|
1931 | 1932 | [(not (string/starts-with? (node-path/basename path) "hls__")) path]) |
1932 | 1933 | *doc-files) |
1933 | 1934 | (range 0 (count *doc-files)))] |
1934 | | - (-> (p/loop [_file-map (export-doc-file (get doc-files 0) conn config <read-file options) |
| 1935 | + (-> (p/loop [_file-map (export-doc-file (get doc-files 0) conn <read-file options) |
1935 | 1936 | i 0] |
1936 | 1937 | (when-not (>= i (dec (count doc-files))) |
1937 | | - (p/recur (export-doc-file (get doc-files (inc i)) conn config <read-file options) |
| 1938 | + (p/recur (export-doc-file (get doc-files (inc i)) conn <read-file options) |
1938 | 1939 | (inc i)))) |
1939 | 1940 | (p/catch (fn [e] |
1940 | 1941 | (notify-user {:msg (str "Import has unexpected error:\n" (.-message e)) |
|
2139 | 2140 | * :log-fn - fn which logs developer messages |
2140 | 2141 | * :rpath-key - keyword used to get relative path in file map. Default to :path |
2141 | 2142 | * :<read-file - fn which reads a file across multiple steps |
| 2143 | + * :<get-file-stat - fn which returns stat of a file path |
2142 | 2144 | * :default-config - default config if config is unable to be read |
2143 | | - * :user-options - map of user specific options. See add-file-to-db-graph for more |
| 2145 | + * :user-options - map of user specific options. See <add-file-to-db-graph for more |
2144 | 2146 | * :<save-config-file - fn which saves a config file |
2145 | 2147 | * :<save-logseq-file - fn which saves a logseq file |
2146 | 2148 | * :<read-and-copy-asset - fn which reads and copies asset file |
|
2174 | 2176 | <read-and-copy-asset |
2175 | 2177 | (merge (select-keys options [:notify-user :set-ui-state :rpath-key]) |
2176 | 2178 | {:assets (get-in doc-options [:import-state :assets])})) |
2177 | | - (export-doc-files conn config doc-files <read-file doc-options) |
| 2179 | + (export-doc-files conn doc-files <read-file doc-options) |
2178 | 2180 | (export-favorites-from-config-edn conn repo-or-conn config {}) |
2179 | 2181 | (export-class-properties conn repo-or-conn) |
2180 | 2182 | (move-top-parent-pages-to-library conn repo-or-conn) |
|
0 commit comments