/
css.clj
44 lines (36 loc) · 1.23 KB
/
css.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns mentat.clerk-utils.css
"Functions for adding custom CSS to Clerk's header."
(:refer-clojure :exclude [set!])
(:require [hiccup.page :as hiccup]
[nextjournal.clerk.view :as view]))
;; ## CSS Customization
(def ^{:doc "Stateful reference to a sequence of custom CSS sources to be
included in Clerk's page when it loads."}
custom-css
(atom []))
(alter-var-root
#'view/include-viewer-css
(fn [old]
(fn [& xs]
(concat
(map hiccup/include-css @custom-css)
(apply old xs)))))
(defn add-css!
"Takes any number of CSS paths and modifies Clerk to include these CSS files in
its header.
Successive calls to [[add-css!]] will append files to the list.
Call [[reset-css!]] to reset, or [[set-css!]] for a non-appending version."
[& entries]
(swap! custom-css into entries))
(defn set-css!
"Takes any number of CSS paths and modifies Clerk to include these CSS files in
its header.
Any call to [[set-css!]] will wipe out any custom CSS already appended.
Call [[reset-css!]] to reset, or [[set-css!]] for a version that appends files
on each call."
[& entries]
(reset! custom-css (into [] entries)))
(defn reset-css!
"Resets Clerk's CSS header list to the default."
[]
(set-css! []))