Skip to content

Commit

Permalink
auto-create nb index
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Nov 11, 2024
1 parent 25731cd commit c8a08a0
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions reval/src/reval/core.clj
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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))

0 comments on commit c8a08a0

Please sign in to comment.