|
42 | 42 |
|
43 | 43 | (defn- add-missing-timestamps |
44 | 44 | "Add updated-at or created-at timestamps if they doesn't exist" |
45 | | - [block] |
46 | | - (let [updated-at (common-util/time-ms) |
47 | | - block (cond-> block |
48 | | - (nil? (:block/updated-at block)) |
49 | | - (assoc :block/updated-at updated-at) |
50 | | - (nil? (:block/created-at block)) |
51 | | - (assoc :block/created-at updated-at))] |
52 | | - block)) |
| 45 | + ([block] |
| 46 | + (add-missing-timestamps block nil)) |
| 47 | + ([block {:keys [file-created-at file-updated-at]}] |
| 48 | + (let [updated-at (or file-updated-at (common-util/time-ms)) |
| 49 | + created-at (or file-created-at updated-at) |
| 50 | + block (cond-> block |
| 51 | + (nil? (:block/updated-at block)) |
| 52 | + (assoc :block/updated-at updated-at) |
| 53 | + (nil? (:block/created-at block)) |
| 54 | + (assoc :block/created-at created-at))] |
| 55 | + block))) |
53 | 56 |
|
54 | 57 | (defn- build-new-namespace-page [block] |
55 | 58 | (let [new-title (ns-util/get-last-part (:block/title block))] |
|
1993 | 1996 | (handle-math) |
1994 | 1997 | (update-block-marker db options) |
1995 | 1998 | (update-block-priority options) |
1996 | | - add-missing-timestamps |
| 1999 | + (add-missing-timestamps options) |
1997 | 2000 | (dissoc :block/format :block.temp/ast-blocks) |
1998 | 2001 | ;; ((fn [x] (prn ::block-out x) x)) |
1999 | 2002 | )] |
|
2008 | 2011 | aliases)))) |
2009 | 2012 |
|
2010 | 2013 | (defn- build-new-page-or-class |
2011 | | - [m db per-file-state all-idents {:keys [user-options journal-created-ats]}] |
| 2014 | + [m db per-file-state all-idents {:keys [user-options journal-created-ats] :as options}] |
2012 | 2015 | (-> (cond-> m |
2013 | 2016 | ;; Fix pages missing :block/title. Shouldn't happen |
2014 | 2017 | (not (:block/title m)) |
|
2017 | 2020 | (update-page-alias (:page-names-to-uuids per-file-state)) |
2018 | 2021 | (journal-created-ats (:block/name m)) |
2019 | 2022 | (assoc :block/created-at (journal-created-ats (:block/name m)))) |
2020 | | - add-missing-timestamps |
| 2023 | + (add-missing-timestamps options) |
2021 | 2024 | (update-page-tags db user-options per-file-state all-idents))) |
2022 | 2025 |
|
2023 | 2026 | (defn- get-page-parents |
|
2476 | 2479 |
|
2477 | 2480 | (defn- extract-pages-and-blocks |
2478 | 2481 | "Main fn which calls graph-parser to convert markdown into data" |
2479 | | - [db file content {:keys [extract-options import-state]}] |
| 2482 | + [db file content {:keys [extract-options import-state file-created-at file-updated-at]}] |
2480 | 2483 | (let [format (common-util/get-format file) |
| 2484 | + with-file-timestamps (fn [node] |
| 2485 | + (cond-> node |
| 2486 | + file-created-at (assoc :block/created-at file-created-at) |
| 2487 | + file-updated-at (assoc :block/updated-at file-updated-at))) |
2481 | 2488 | extract-options' (merge {:block-pattern (get-block-pattern format) |
2482 | 2489 | :date-formatter "MMM do, yyyy" |
2483 | 2490 | :uri-encoded? false |
|
2490 | 2497 | (cond (contains? #{:org :markdown :md} format) |
2491 | 2498 | (-> (extract/extract file content extract-options') |
2492 | 2499 | (update :pages (fn [pages] |
2493 | | - (map #(dissoc % :block.temp/original-page-name) pages))) |
2494 | | - (update :blocks fix-extracted-block-tags-and-refs)) |
| 2500 | + (map #(-> % |
| 2501 | + (dissoc :block.temp/original-page-name) |
| 2502 | + with-file-timestamps) |
| 2503 | + pages))) |
| 2504 | + (update :blocks (fn [blocks] |
| 2505 | + (fix-extracted-block-tags-and-refs |
| 2506 | + (map with-file-timestamps blocks))))) |
2495 | 2507 |
|
2496 | 2508 | :else |
2497 | 2509 | (when-not (re-find #"whiteboards/.*\.edn$" (str file)) |
|
2640 | 2652 |
|
2641 | 2653 | (defn- export-doc-file |
2642 | 2654 | [{:keys [path idx] :as file} conn <read-file |
2643 | | - {:keys [notify-user set-ui-state <export-file] |
| 2655 | + {:keys [notify-user set-ui-state <export-file <get-file-stat] |
2644 | 2656 | :or {set-ui-state (constantly nil) |
2645 | 2657 | <export-file (fn <export-file [conn m opts] |
2646 | 2658 | (<add-file-to-db-graph conn (:file/path m) (:file/content m) opts))} |
|
2649 | 2661 | (-> (p/let [_ (set-ui-state [:graph/importing-state :current-idx] (inc idx)) |
2650 | 2662 | _ (set-ui-state [:graph/importing-state :current-page] path) |
2651 | 2663 | content (<read-file file) |
| 2664 | + stat (when (fn? <get-file-stat) |
| 2665 | + (<get-file-stat (or (:fs-path file) path))) |
| 2666 | + created-at (or (:birthtime stat) (some-> stat .-birthtime)) |
| 2667 | + modified-at (or (:mtime stat) (some-> stat .-mtime) (:last-modified-at file)) |
2652 | 2668 | m {:file/path path :file/content content} |
2653 | | - _ (<export-file conn m (dissoc options :set-ui-state :<export-file))] |
| 2669 | + export-options (cond-> (dissoc options :set-ui-state :<export-file) |
| 2670 | + created-at (assoc :file-created-at (.getTime created-at)) |
| 2671 | + modified-at (assoc :file-updated-at (.getTime modified-at))) |
| 2672 | + _ (<export-file conn m export-options)] |
2654 | 2673 | ;; returning val results in smoother ui updates |
2655 | 2674 | m) |
2656 | 2675 | (p/catch (fn [error] |
|
0 commit comments