Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
The static-site generator behind jlt-commons project documentation. A project
writes markdown; this turns it into a site that GitHub Pages serves.

It is a small babashka program, and `build`/`clean` also run under `jolt`
(jolt reads `bb.edn` tasks directly). `test` and `serve` still need `bb`:
jolt doesn't bundle `clojure.test` or `http-kit`. External dependencies
It is a small babashka program, and `build`, `clean` and `test` also run
under `jolt` (jolt reads `bb.edn` tasks directly). `serve` still needs `bb`:
it binds the port with `http-kit`, which jolt doesn't have. External dependencies
(`markdown-clj`, `selmer`, and the `jolt-lang/yaml`/`jolt-lang/time` shims
that make those two resolve under jolt) are fetched on first run.

Expand Down Expand Up @@ -85,15 +85,15 @@ callout.
```bash
jolt run build ../your-project # generate ../your-project/_site/
jolt run clean ../your-project # delete the build output
bb test # the test suite
jolt test # the test suite (or bb test)
bb serve ../your-project # build, then serve, honouring :base-path
bb serve ../your-project 4000
```

`build`/`clean` run under either tool. Under `jolt` it's `jolt run <task>`,
not bare `jolt <task>`: `build` collides with jolt's own native
`build -m NS` compiler subcommand. `test` and `serve` stay `bb`-only,
since jolt doesn't bundle `clojure.test` or `http-kit`.
`build`, `clean` and `test` run under either tool. Under `jolt` it's
`jolt run <task>`, not bare `jolt <task>`: `build` collides with jolt's own
native `build -m NS` compiler subcommand. `serve` stays `bb`-only, since it
uses `http-kit`.

`_site/` is generated. Add it to the project's `.gitignore`.

Expand Down
10 changes: 5 additions & 5 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
;; unchanged (bb already has real java.time; this just adds tick's
;; API on top of it).
io.github.jolt-lang/time {:git/url "https://github.com/jolt-lang/time.git"
:git/sha "abeee49974c2c4efa2fa75c96d9a379822c6815f"}}
:git/sha "b6d64a9ea4a71c6d40f66d0c3c9c4fff28f1bf8c"}}
:tasks
{;; tick.core first, unconditionally -- see the io.github.jolt-lang/time
;; comment above :deps. Everything after it in this list, and every
Expand All @@ -60,11 +60,11 @@
(println "docs-engine — the jlt-commons documentation site generator\n")
(println " jolt run build <project> generate <project>/_site/")
(println " jolt run clean <project> delete <project>/_site/")
(println " bb test run the test suite")
(println " jolt test run the test suite")
(println " bb serve <project> [port] build, then serve at localhost:3000\n")
(println "build/clean run under either tool (jolt run <task>, not bare jolt <task>:")
(println "build collides with jolt's own build -m NS subcommand). test/serve stay")
(println "bb-only: jolt doesn't bundle clojure.test or http-kit.\n")
(println "build/clean/test run under either tool (jolt run <task>, not bare jolt <task>:")
(println "build collides with jolt's own build -m NS subcommand). serve stays")
(println "bb-only: it uses http-kit.\n")
(println "A project configures itself in docs/site.edn. See README.md."))}

test {:doc "Run the full test suite"
Expand Down
13 changes: 6 additions & 7 deletions src/site/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,12 @@
;;
;; Everything below builds a plain Ring handler `(fn [req]) -> {:status
;; :headers :body}` and touches no HTTP-server library at all, so it costs
;; build/clean/test nothing. site.serve (bb/JVM) and site.serve.jolt (jolt)
;; are the two thin wrappers that actually bind a port, each requiring the
;; one HTTP-server library their own host has: org.httpkit.server for
;; bb/JVM, ring-chez.adapter for jolt. Splitting it this way is what makes
;; build/clean/test loadable under jolt at all — org.httpkit.server isn't
;; resolvable there, and previously every task here required it via this
;; namespace regardless of whether it ever started a server.
;; build/clean/test nothing. site.serve is the thin wrapper that actually
;; binds a port, with org.httpkit.server, so `serve` runs under bb only.
;; Splitting it this way is what makes build/clean/test loadable under jolt
;; at all — org.httpkit.server isn't resolvable there, and previously every
;; task here required it via this namespace regardless of whether it ever
;; started a server.

(defn- content-type [path]
(cond
Expand Down
8 changes: 2 additions & 6 deletions src/site/serve.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
library involved at all; this namespace is the thin wrapper around
org.httpkit.server that turns it into a running server.

Jolt never loads this file. site/serve.jolt is the jolt-native twin
(ring-chez.adapter instead of http-kit) — jolt's require resolves
<ns>.jolt before <ns>.clj (see the docs-engine README, \"Local preview
server: two hosts, one namespace\"), so the two never collide, and
babashka/JVM never see the .jolt file at all, since their own require
only ever looks for .clj/.cljc."
http-kit isn't available under jolt, so `serve` is bb-only; no other
task requires this namespace."
(:require [org.httpkit.server :as hk]
[site.core :as core]))

Expand Down
4 changes: 2 additions & 2 deletions test/site/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns site.core-test
(:require [babashka.fs :as fs]
[clojure.java.io :as io]
[cheshire.core :as json]
[clojure.data.json :as json]
[clojure.string :as str]
[clojure.test :refer [deftest is testing]]
[site.core :as core]))
Expand Down Expand Up @@ -90,7 +90,7 @@
{:out (:output-dir site)
:site site
:index (let [f (io/file (:output-dir site) "search-documents.json")]
(when (fs/exists? f) (json/parse-string (slurp f))))
(when (fs/exists? f) (json/read-str (slurp f))))
:doc (when-not readme? (slurp (io/file (:output-dir site) "guide" "index.html")))
:plain (slurp (io/file (:output-dir site) "guide" "plain.html"))
:home (slurp (io/file (:output-dir site) "index.html"))}))))
Expand Down
6 changes: 3 additions & 3 deletions test/site/markdown_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@
;; this pins the JVM-side behavior this function must keep matching).
(testing "preamble before the first heading becomes its own leading chunk"
(is (= ["pre" "<h2 id=\"a\">A</h2>mid" "<h2 id=\"b\">B</h2>end"]
(md/split-before-h2-headings "pre<h2 id=\"a\">A</h2>mid<h2 id=\"b\">B</h2>end"))))
(#'md/split-before-h2-headings "pre<h2 id=\"a\">A</h2>mid<h2 id=\"b\">B</h2>end"))))
(testing "no preamble when the body starts exactly at a heading"
(is (= ["<h2 id=\"a\">A</h2>mid" "<h2 id=\"b\">B</h2>"]
(md/split-before-h2-headings "<h2 id=\"a\">A</h2>mid<h2 id=\"b\">B</h2>"))))
(#'md/split-before-h2-headings "<h2 id=\"a\">A</h2>mid<h2 id=\"b\">B</h2>"))))
(testing "no headings at all returns the whole string as one chunk"
(is (= ["just prose, no headings"]
(md/split-before-h2-headings "just prose, no headings")))))
(#'md/split-before-h2-headings "just prose, no headings")))))

(deftest collapse-long-sections-leaves-short-pages-untouched
;; Below collapse-min-long-sections (5) the page reads as prose, and
Expand Down
4 changes: 2 additions & 2 deletions test/site/search_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns site.search-test
(:require [cheshire.core :as json]
(:require [clojure.data.json :as json]
[clojure.string :as str]
[clojure.test :refer [deftest is testing]]
[site.markdown :as md]
Expand All @@ -16,7 +16,7 @@
"é → ü"
""]]
(is (= [{"text" s}]
(json/parse-string (search/->json [{:text s}]))))))
(json/read-str (search/->json [{:text s}]))))))
(testing "empty seq produces empty array"
(is (= "[]" (search/->json []))))
(testing "U+2028 LINE SEPARATOR is escaped as \\u2028, not raw character"
Expand Down
Loading