Skip to content

Commit

Permalink
No need to extract classes from viewer EDN blob
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Jul 27, 2023
1 parent 9da9136 commit 376b4fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion resources/stylesheets/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
darkMode: "class",
content: ["./tw/**/*.{js,edn,clj,cljs}"],
content: ["./tw/**/*.{js,clj,cljc,cljs}"],
safelist: ['dark'],
theme: {
extend: {},
Expand Down
23 changes: 11 additions & 12 deletions src/nextjournal/clerk/builder.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
[nextjournal.clerk.viewer :as viewer]
[nextjournal.clerk.webserver :as webserver]
[nextjournal.clerk.config :as config])
(:import (java.net URL)))
(:import (java.io IOException)
(java.net URL)))

(def clerk-docs
(into ["CHANGELOG.md"
Expand Down Expand Up @@ -292,7 +293,8 @@
(def create-parent-dirs (comp fs/create-dirs fs/parent))

(def files-with-tw-classes
#{"render.cljs"
#{"viewer.cljc"
"render.cljs"
"render/panel.cljs"
"render/code.cljs"
"render/navbar.cljs"
Expand All @@ -314,24 +316,21 @@
;; are treated as ES modules and this is not the case of our tw config.
(spit tw-input (slurp (io/resource "stylesheets/viewer.css")))

;; extract classes from built-in index
(fs/copy builtin-index (fs/path tw-folder "index.clj") {:replace-existing true})

(if (custom-js-bundle? resource->url)
(spit (str tw-folder "/viewer.js")
(slurp (let [js-url (get resource->url "/js/viewer.js")]
(cond->> js-url (view/relative? js-url) (str out-path fs/file-separator)))))
(do
(println "\nTailwind: using cljs source files as input")
(println "\nTailwind: using Clerk source files as content")
(doseq [[src dest] (map (juxt #(io/resource (str "nextjournal/clerk/" %))
#(doto (fs/path tw-folder %) create-parent-dirs)) files-with-tw-classes)]
(fs/copy src dest {:replace-existing true}))))

(doseq [{:keys [file viewer]} docs]
(spit (let [path (fs/path tw-folder (str/replace (str file) #"\.(cljc?|md)$" ".edn"))]
(create-parent-dirs path)
(str path))
(pr-str viewer)))
;; copy content files
(doseq [{:keys [file]} docs]
(fs/copy file ;; file is either a relative path or an URL
(doto (fs/path tw-folder (str/replace (str file) #"^file:/" ""))
create-parent-dirs println) {:replace-existing true}))

(let [tw-command (if (zero? (:exit (try (sh "which tailwindcss") (catch Throwable _)))) "tailwindcss" "npx tailwindcss")
{:as ret :keys [out err exit]}
Expand All @@ -340,7 +339,7 @@
"--config" tw-config
"--output" tw-output
"--minify")
(catch java.io.IOException _
(catch IOException _
(throw (Exception. "Clerk could not find the `tailwindcss` executable. Please install it using `npm install -D tailwindcss @tailwindcss/typography` and try again."))))]
(println err)
(println out)
Expand Down

0 comments on commit 376b4fa

Please sign in to comment.