|
115 | 115 | index (assoc :index (str index)))))
|
116 | 116 |
|
117 | 117 | #_(process-build-opts {:index 'book.clj})
|
| 118 | +(defn build-path->url [{:as opts :keys [bundle?]} docs] |
| 119 | + (into {} |
| 120 | + (map (comp (juxt identity #(cond-> (->> % (view/map-index opts) strip-index) (not bundle?) ->html-extension)) |
| 121 | + :file)) |
| 122 | + docs)) |
| 123 | +#_(build-path->url {:bundle? false} [{:file "notebooks/foo.clj"} {:file "index.clj"}]) |
| 124 | +#_(build-path->url {:bundle? true} [{:file "notebooks/foo.clj"} {:file "index.clj"}]) |
118 | 125 |
|
119 | 126 | (defn build-static-app-opts [{:as opts :keys [bundle? out-path browse? index]} docs]
|
120 |
| - (let [paths (mapv :file docs) |
121 |
| - path->doc (into {} (map (juxt :file :viewer)) docs) |
122 |
| - path->url (into {} (map (juxt identity #(cond-> (->> % (view/map-index opts) strip-index) (not bundle?) ->html-extension))) paths)] |
123 |
| - (assoc opts :bundle? bundle? :path->doc path->doc :paths (vec (keys path->doc)) :path->url path->url))) |
| 127 | + (let [path->doc (into {} (map (juxt :file :viewer)) docs)] |
| 128 | + (assoc opts |
| 129 | + :bundle? bundle? |
| 130 | + :path->doc path->doc |
| 131 | + :paths (vec (keys path->doc)) |
| 132 | + :path->url (build-path->url opts docs)))) |
124 | 133 |
|
125 | 134 | (defn ssr!
|
126 | 135 | "Shells out to node to generate server-side-rendered html."
|
|
239 | 248 | "/css/viewer.css" (viewer/store+get-cas-url! (assoc opts :ext "css") (fs/read-all-bytes tw-output)))
|
240 | 249 | (fs/delete-tree tw-folder)))
|
241 | 250 |
|
242 |
| -(defn build-static-app! [opts] |
| 251 | +(defn build-static-app! [{:as opts :keys [bundle?]}] |
243 | 252 | (let [{:as opts :keys [download-cache-fn upload-cache-fn report-fn compile-css?]}
|
244 | 253 | (process-build-opts opts)
|
245 | 254 | {:keys [expanded-paths error]} (try {:expanded-paths (expand-paths opts)}
|
|
267 | 276 | (report-fn {:stage :downloading-cache})
|
268 | 277 | (let [{duration :time-ms} (eval/time-ms (download-cache-fn state))]
|
269 | 278 | (report-fn {:stage :done :duration duration})))
|
270 |
| - state (mapv (fn [doc idx] |
| 279 | + state (mapv (fn [{:as doc :keys [file]} idx] |
271 | 280 | (report-fn {:stage :building :doc doc :idx idx})
|
272 | 281 | (let [{result :result duration :time-ms} (eval/time-ms
|
273 | 282 | (try
|
274 |
| - (let [doc (eval/eval-analyzed-doc doc)] |
| 283 | + (let [doc (binding [viewer/doc-url |
| 284 | + (fn [path] |
| 285 | + (let [url (get (build-path->url opts state) path)] |
| 286 | + (if bundle? |
| 287 | + (str "#/" url) |
| 288 | + (str (viewer/relative-root-prefix-from file) url))))] |
| 289 | + (eval/eval-analyzed-doc doc))] |
275 | 290 | (assoc doc :viewer (view/doc->viewer (assoc opts :inline-results? true) doc)))
|
276 | 291 | (catch Exception e
|
277 | 292 | {:error e})))]
|
|
0 commit comments