|
552 | 552 | {:as to-present :nextjournal/keys [auto-expand-results?]} (merge (dissoc (->opts wrapped-value) :!budget :nextjournal/budget) |
553 | 553 | (dissoc cell :result ::doc) ;; TODO: reintroduce doc once we know why it OOMs the static build on CI (some walk issue probably) |
554 | 554 | opts-from-block |
555 | | - (ensure-wrapped-with-viewers (or viewers (get-viewers (get-*ns*))) value)) |
| 555 | + (ensure-wrapped-with-viewers (or viewers (get-viewers (get-*ns*))) value) |
| 556 | + (when blob-id {:nextjournal/blob-id blob-id})) |
556 | 557 | presented-result (-> (present to-present) |
557 | 558 | (update :nextjournal/render-opts |
558 | 559 | (fn [{:as opts existing-id :id}] |
|
939 | 940 |
|
940 | 941 | (defn ->opts [wrapped-value] |
941 | 942 | (select-keys wrapped-value [:nextjournal/budget :nextjournal/css-class :nextjournal/width :nextjournal/render-opts |
942 | | - :nextjournal/render-evaluator |
943 | | - :!budget :store!-wrapped-value :store!-viewer |
| 943 | + :nextjournal/render-evaluator :nextjournal/blob-id |
| 944 | + :!budget :store!-wrapped-value :store!-viewer :presentation-cache |
944 | 945 | :present-elision-fn :path :offset])) |
945 | 946 |
|
946 | 947 | (defn inherit-opts [{:as wrapped-value :nextjournal/keys [viewers]} value path-segment] |
947 | 948 | (-> (ensure-wrapped-with-viewers viewers value) |
948 | | - (merge (select-keys (->opts wrapped-value) [:!budget :store!-wrapped-value :store!-viewer |
949 | | - :present-elision-fn :nextjournal/budget :path])) |
| 949 | + (merge (select-keys (->opts wrapped-value) [:!budget :store!-wrapped-value :store!-viewer :presentation-cache |
| 950 | + :present-elision-fn :nextjournal/budget :path :nextjournal/blob-id])) |
950 | 951 | (update :path (fnil conj []) path-segment))) |
951 | 952 |
|
952 | 953 | (defn present-ex-data [parent throwable-map] |
|
996 | 997 | (def image-viewer |
997 | 998 | {#?@(:bb [] |
998 | 999 | :clj [:pred #(instance? BufferedImage %) |
999 | | - :transform-fn (fn [{image :nextjournal/value}] |
1000 | | - (-> {:nextjournal/value (buffered-image->bytes image) |
1001 | | - :nextjournal/content-type "image/png" |
1002 | | - :nextjournal/width (image-width image)} |
1003 | | - mark-presented))]) |
| 1000 | + :transform-fn (fn [{image :nextjournal/value |
| 1001 | + blob-id :nextjournal/blob-id |
| 1002 | + :keys [presentation-cache] |
| 1003 | + :as wrapped-value}] |
| 1004 | + (let [cache-path [blob-id (:path wrapped-value)] |
| 1005 | + bytes (or (when presentation-cache |
| 1006 | + (get-in @presentation-cache cache-path)) |
| 1007 | + (let [b (buffered-image->bytes image)] |
| 1008 | + (when (and presentation-cache blob-id) |
| 1009 | + (swap! presentation-cache assoc-in cache-path b)) |
| 1010 | + b))] |
| 1011 | + (-> {:nextjournal/value bytes |
| 1012 | + :nextjournal/content-type "image/png" |
| 1013 | + :nextjournal/width (image-width image)} |
| 1014 | + mark-presented)))]) |
1004 | 1015 | :name `image-viewer |
1005 | 1016 | :render-fn '(fn [blob-or-url] [:div.flex.flex-col.items-center.not-prose |
1006 | 1017 | [:img {:src #?(:clj (nextjournal.clerk.render/url-for blob-or-url) |
|
0 commit comments