|
44 | 44 | ([{:keys [out-dir]} page]
|
45 | 45 | (println+flush "📷 Starting screenshotting…")
|
46 | 46 | (p/let [og-captures (.locator page ".open-graph-image-capture")
|
| 47 | + _ (.addStyleTag page #js {:content ".sticky-table-header { display: none !important; box-shadow: none !important;}"}) |
47 | 48 | og-captures-count (.count og-captures)
|
48 | 49 | results (if (< 0 og-captures-count)
|
49 | 50 | og-captures
|
|
56 | 57 | (p/let [res (.nth results i)
|
57 | 58 | bounds (.boundingBox res)]
|
58 | 59 | (if true #_ (<= 250 (.-height bounds))
|
59 |
| - (p/let [id (.getAttribute res "data-block-id") |
60 |
| - imgs (.locator res "img") |
61 |
| - imgs-count (.count imgs) |
62 |
| - single-image? (= imgs-count 1) |
63 |
| - _ (println+flush (str "🔍 Result #" (inc i) " contains " imgs-count " " (if single-image? "image" "images") ".")) |
64 |
| - subject (if single-image? (.first imgs) res) |
65 |
| - _ (println+flush (str "📸 Screenshotting result #" (inc i) " - ID: " id |
66 |
| - " (" (if single-image? "single image" "entire result") ")" |
67 |
| - " with bounds " (.-width bounds) "×" (.-height bounds))) |
68 |
| - buffer (.screenshot subject) |
69 |
| - base64 (.toString buffer "base64") |
70 |
| - image-uri (str "data:image/png;base64," base64) |
71 |
| - _ (.evaluate res (str "nextjournal.clerk.trim_image.append_trimmed_image(" |
72 |
| - (pr-str image-uri) "," (pr-str (str "res-" i)) ")")) |
73 |
| - trimmed-res (.locator page (str "#res-" i)) |
74 |
| - trimmed-bounds (.boundingBox trimmed-res)] |
75 |
| - (println+flush (str "🔪 Trimming result #" (inc i) " to bounds " (.-width trimmed-bounds) "×" (.-height trimmed-bounds))) |
76 |
| - (.screenshot trimmed-res #js {:path (->path out-dir (str (if id (name (edn/read-string id)) (str "result-" (inc i))) ".png"))})) |
77 |
| - (println+flush "🦘 Skipping result with bounds" (str (.-width bounds) "×" (.-height bounds)))) |
| 60 | + (p/let [id (.getAttribute res "data-block-id") |
| 61 | + imgs (.locator res "img") |
| 62 | + imgs-count (.count imgs) |
| 63 | + single-image? (= imgs-count 1) |
| 64 | + _ (println+flush (str "🔍 Result #" (inc i) " contains " imgs-count " " (if single-image? "image" "images") ".")) |
| 65 | + subject (if single-image? (.first imgs) res) |
| 66 | + _ (println+flush (str "📸 Screenshotting result #" (inc i) " - ID: " id |
| 67 | + " (" (if single-image? "single image" "entire result") ")" |
| 68 | + " with bounds " (.-width bounds) "×" (.-height bounds))) |
| 69 | + buffer (.screenshot subject) |
| 70 | + base64 (.toString buffer "base64") |
| 71 | + image-uri (str "data:image/png;base64," base64) |
| 72 | + _ (.evaluate res (str "nextjournal.clerk.trim_image.append_trimmed_image(" |
| 73 | + (pr-str image-uri) "," (pr-str (str "res-" i)) ")")) |
| 74 | + trimmed-res (.locator page (str "#res-" i)) |
| 75 | + trimmed-bounds (.boundingBox trimmed-res)] |
| 76 | + (println+flush (str "🔪 Trimming result #" (inc i) " to bounds " (.-width trimmed-bounds) "×" (.-height trimmed-bounds))) |
| 77 | + (.screenshot trimmed-res #js {:path (->path out-dir (str (if id (name (edn/read-string id)) (str "result-" (inc i))) ".png"))})) |
| 78 | + (println+flush "🦘 Skipping result with bounds" (str (.-width bounds) "×" (.-height bounds)))) |
78 | 79 | (p/recur (inc i)))
|
79 | 80 | (println+flush "✅ Done."))))))
|
80 | 81 |
|
|
0 commit comments