From c8a08a0fcc4c2d0abbbc35d7fc834de2d01066b3 Mon Sep 17 00:00:00 2001 From: awb99 Date: Mon, 11 Nov 2024 12:47:29 -0500 Subject: [PATCH] auto-create nb index --- reval/src/reval/core.clj | 46 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/reval/src/reval/core.clj b/reval/src/reval/core.clj index e275aa2..94f388d 100644 --- a/reval/src/reval/core.clj +++ b/reval/src/reval/core.clj @@ -1,12 +1,36 @@ (ns reval.core (:require [taoensso.timbre :as timbre :refer [info]] + [babashka.fs :as fs] [clj-service.core :refer [expose-functions]] [dali.store.file :refer [create-dali-file-store]] [reval.document.collection :as nbcol] [reval.default] ; side effects to include all default converters )) +(def nb-welcome + {:meta {:ns "welcome"} + :content + [{:code "(println \"Welcome to Notebook Viewer \")" + :result ^{:dali true} + {:viewer-fn 'dali.viewer.hiccup/hiccup + :data [:h1.text-blue-800 "Welcome to Notebook Viewer!"]} + :out "Welcome to Notebook Viewer"}]}) + +(defn- save-welcome [{:keys [rdocument]}] + (info "generate index notebook.. ") + (fs/create-dirs (:fpath rdocument)) + (spit + (str (:fpath rdocument) "/welcome.edn") + nb-welcome)) + +(defn build-notebook-index [{:keys [rdocument collections] :as this}] + (info "build collection index for collections: " collections) + (fs/create-dirs (:fpath rdocument)) + (spit + (str (:fpath rdocument) "/notebooks.edn") + (nbcol/collections-ns-summary collections))) + (defn start-reval [{:keys [clj reval-role rdocument collections] :or {rdocument {:fpath ".reval/public/rdocument" :rpath "/r/rdocument" @@ -39,29 +63,13 @@ 'reval.dali.eval/dali-eval-blocking] :permission reval-role :fixed-args [env]})) + (build-notebook-index env) + (save-welcome env) env)) -(def nb-welcome - {:meta {:ns "welcome"} - :content - [{:code "(println \"Welcome to Notebook Viewer \")" - :result ^{:dali true} - {:viewer-fn 'dali.viewer.hiccup/hiccup - :data [:h1.text-blue-800 "Welcome to Notebook Viewer!"]} - :out "Welcome to Notebook Viewer"}]}) - -(defn- save-welcome [{:keys [rdocument]}] - (spit - (str (:fpath rdocument) "/welcome.edn") - nb-welcome)) - (defn eval-collections [{:keys [rdocument collections] :as this}] (info "eval collections.. ") (nbcol/eval-collections this collections) - (info "build collection index for collections: " collections) - (spit - (str (:fpath rdocument) "/notebooks.edn") - (nbcol/collections-ns-summary collections)) - (info "generate index notebook.. ") + (build-notebook-index this) (save-welcome this))