<commit_before>(ns qcon.web
  (:require
   [bidi.bidi :refer (->Redirect)]
   [jig.bidi :refer (add-bidi-routes)]
   [stencil.core :as stencil]
   [jig.util :refer (satisfying-dependency)]
   jig)
  (:import (jig Lifecycle))
  )

(defn index-page [loader]
  (assert loader "Loader is nil")
  (fn [req]
    (assert (loader "slides.html") (format "Can't find slides.html, loader is %s" loader))
    {:status 200 :body (stencil/render (loader "slides.html") {:content "Hello QCon!"})}))

(defn make-handlers [loader]
  (let [p (promise)]
    @(deliver p {:index (index-page loader)})))

(defn make-routes [handlers]
  ["/"
   [["index.html" (:index handlers)]
    ["" (->Redirect 307 (:index handlers))]]])

(defn get-template-loader [system config]
  (if-let [{id :jig/id} (satisfying-dependency system config 'jig.stencil/StencilLoader)]
    (if-let [template-loader (get-in system [id :jig.stencil/loader])]
      template-loader
      (throw (ex-info (format "Failed to find lookup template loader in system at path %s"
                              [id :jig.stencil/loader])
                      {:path [id :jig.stencil/loader]})))
    (throw (ex-info (format "Component must depend on a %s component" 'jig.stencil/StencilLoader) {}))
    )
  )

(deftype Website [config]
  Lifecycle
  (init [_ system] system)
  (start [_ system]
    (let [loader (get-template-loader system config)]
      (-> system
          (assoc :loader loader)
          (add-bidi-routes config (make-routes (make-handlers loader))))))
  (stop [_ system] system))
<commit_msg>Serve plan.org<commit_after>(ns qcon.web
  (:require
   [bidi.bidi :refer (->Redirect)]
   [jig.bidi :refer (add-bidi-routes)]
   [clojure.java.io :as io]
   [stencil.core :as stencil]
   [jig.util :refer (satisfying-dependency)]
   jig)
  (:import (jig Lifecycle))
  )

(defn index-page [loader plan]
  (assert loader "Loader is nil")
  (fn [req]
    (assert (loader "slides.html") (format "Can't find slides.html, loader is %s" loader))
    {:status 200 :body (stencil/render (loader "slides.html") {:content (slurp plan)})}))

(defn make-handlers [loader plan]
  (let [p (promise)]
    @(deliver p {:index (index-page loader plan)})))

(defn make-routes [handlers]
  ["/"
   [["index.html" (:index handlers)]
    ["" (->Redirect 307 (:index handlers))]]])

(defn get-template-loader [system config]
  (if-let [{id :jig/id} (satisfying-dependency system config 'jig.stencil/StencilLoader)]
    (if-let [template-loader (get-in system [id :jig.stencil/loader])]
      template-loader
      (throw (ex-info (format "Failed to find lookup template loader in system at path %s"
                              [id :jig.stencil/loader])
                      {:path [id :jig.stencil/loader]})))
    (throw (ex-info (format "Component must depend on a %s component" 'jig.stencil/StencilLoader) {}))
    )
  )

(deftype Website [config]
  Lifecycle
  (init [_ system] system)
  (start [_ system]

    (clojure.pprint/pprint config)
    (let [loader (get-template-loader system config)
          plan (io/file (-> config :jig/project :project-file (.getParentFile)) "plan.org")]
      (-> system
          (assoc :loader loader)
          (add-bidi-routes config (make-routes (make-handlers loader plan))))))
  (stop [_ system] system))

{'fraction_non_alphanumeric': 0.16209628275441804, 'fraction_numerical': 0.003656307129798903, 'mean_word_length': 3.1347607052896724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3575961', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1133, 'n_words': 305}