Skip to content

Commit

Permalink
Build site using new API
Browse files Browse the repository at this point in the history
This includes an extremely kludgy use of eval to get the page <style> tags
working properly, but it demonstrates how simple and effective the new API can be.
  • Loading branch information
respatialized committed Jan 9, 2024
1 parent 22e83f0 commit af78a21
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 121 deletions.
70 changes: 44 additions & 26 deletions dev/site/fabricate/dev/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
[site.fabricate.prototype.read :as read]
[site.fabricate.prototype.page :as page]
[site.fabricate.prototype.html :as html]
[garden.core :as garden]
[garden.stylesheet :refer [at-import]]
[babashka.fs :as fs]
[hiccup.page]
[hiccup.core :as hiccup]
[clojure.string :as str]
[clojure.java.io :as io]))


(defn create-dir-recursive
[target-dir]
(->> (str/split (str (fs/relativize (fs/cwd) (fs/path (fs/cwd) target-dir)))
(re-pattern fs/file-separator))
(->> (fs/path (fs/cwd) target-dir)
(fs/relativize (fs/cwd))
fs/components
(reduce (fn [paths path] (conj paths (fs/path (peek paths) path))) [])
(filter #(not (fs/exists? %)))
(run! fs/create-dir)))
Expand Down Expand Up @@ -93,9 +97,11 @@
[entry]
(let [parsed-page (read/parse (slurp (:site.fabricate.source/location entry)))
evaluated-page (read/eval-all parsed-page)
page-metadata (page/lift-metadata evaluated-page
(last (read/get-metadata
parsed-page)))
page-metadata (update (page/lift-metadata evaluated-page
(last (read/get-metadata
parsed-page)))
:page-style
eval)
hiccup-page [:html (page/doc-header page-metadata)
[:body
[:main
Expand All @@ -122,22 +128,34 @@
;; (defmethod assemble "index.html" [entry] (assemble-index entry))



(defn write-hiccup-html!
"Generate HTML from Hiccup data and write it to the given file."
[hiccup-page-data output-file]
(spit output-file (hiccup.page/html5 hiccup-page-data)))
(let [parent-dir (fs/parent output-file)]
(create-dir? parent-dir)
(spit output-file (hiccup/html hiccup-page-data))))

(defn subpath
([dir p] (apply fs/path (drop 1 (fs/components (fs/relativize dir p)))))
([p] (subpath (fs/cwd) p)))

(comment
(fs/parent "docs/README.md")
(subpath "docs/path/to/some/file"))

(defn output-path
[input-file output-location]
(cond (fs/directory? output-location)
(fs/file (str output-location "/" (fs/file-name input-file)))
(cond (fs/directory? output-location) (fs/file (fs/path output-location
(subpath input-file)))
(instance? java.io.File output-location) output-location))

(defmethod api/produce! [:hiccup :html]
[entry]
(let [output-file (fs/file (str (output-path
(:site.fabricate.source/location entry)
(fs/strip-ext
(fs/strip-ext
(:site.fabricate.source/location
entry)))
(:site.fabricate.page/location entry))
".html"))]
(write-hiccup-html! (:site.fabricate.document/data entry) output-file)
Expand All @@ -147,23 +165,23 @@

(defmethod api/produce! [:markdown :markdown]
[entry]
(let [output-file (fs/file (str (output-path
(:site.fabricate.source/location entry)
(:site.fabricate.page/location entry))
".md"))]
(let [output-file (fs/file (output-path
(:site.fabricate.source/location entry)
(:site.fabricate.page/location entry)))]
(spit output-file (:site.fabricate.document/data entry))
(assoc entry :site.fabricate.page/output output-file)))

(defn doc->page
[{:keys [site.fabricate.document/title site.fabricate.document/data
site.fabricate.document/id],
:as entry}]
(assoc entry
:site.fabricate.page/data data
:site.fabricate.page/title title
:site.fabricate.page/id id))



(comment
(api/plan! setup-tasks options))
(require '[http.server :as server])
(defonce srv
(server/start {:cors-allow-headers nil,
:dir (str (fs/path (fs/cwd) "docs")),
:port 8002,
:no-cache true}))
(let [entries (api/plan! setup-tasks options)
assembled-entries (api/combine []
{:site.fabricate.api/options options,
:site.fabricate.api/entries entries})]
(api/construct! [] assembled-entries))
(garden/css styles/docs)
(run! fs/delete (fs/glob "docs" "**.html")))
14 changes: 7 additions & 7 deletions pages/background/finite-schema-machines.html.fab
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
✳(ns site.fabricate.docs.background.fsm
(:require [site.fabricate.prototype.page :refer :all]
[site.fabricate.prototype.read :as read]
[site.fabricate.styles :as styles]
[clojure.repl :as repl]
[garden.core :as garden]
[garden.stylesheet :refer [at-import]])) πŸ”š
✳ (def metadata
(:require [site.fabricate.prototype.page :refer :all]
[site.fabricate.prototype.read :as read]
[site.fabricate.dev.styles :as styles]
[clojure.repl :as repl]
[garden.core :as garden]
[garden.stylesheet :refer [at-import]])) πŸ”š
✳ (def metadata
{:title "Organizing computation with Finite Schema Machines"
:description "Using precise schemas to map from data states to functions in Clojure."
:page-style
Expand Down
4 changes: 2 additions & 2 deletions pages/design/queue.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[site.fabricate.prototype.write :as write]
[garden.core :as garden]
[garden.stylesheet :as stylesheet]
[site.fabricate.styles :as styles]
[site.fabricate.dev.styles :as styles]
[site.fabricate.prototype.page :as page])) πŸ”š

✳(def metadata {:title "Design Doc for Work Queue"
Expand All @@ -29,4 +29,4 @@ Wrapping a PersistentQueue in a atom may be the way to obtain a synchronization

The page-rerendering loop could be implemented via ✳=[:code "future"]πŸ”š. Since the contents of the page aren't actually needed by the main loop of Fabricate until they are to be written to output HTML, there could simply be a queue of Futures, executed in the background, then dereferenced sequentially when the program needs to write. This atomic operation could also ✳=[:code "swap!"]πŸ”š the finished page into an atom containing all the "current" pages.

It isn't at all clear to me that it needs to be more complicated than this. ✳=[:code "core.async"]πŸ”š is probably overkill at this point.
It isn't at all clear to me that it needs to be more complicated than this. ✳=[:code "core.async"]πŸ”š is probably overkill at this point.
27 changes: 14 additions & 13 deletions pages/extended-forms.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
[garden.core :as garden]
[garden.stylesheet :refer [at-import]]))πŸ”š

✳(def page-style
(garden/css
(list
(at-import "https://fonts.googleapis.com/css2?family=Zen+Kaku+Gothic+New:wght@300;400;500;700;900&display=swap")
[:body {:font-family "'Zen Kaku Gothic New', sans-serif"
:max-width "60ch"}]
[:h1 {:font-size "3rem"
:font-weight "900"
:max-width "90ch"}]
[:.cols-2 {:display "flex"}]
[:.col {:flex "50%"}]
)))πŸ”š
✳(def page-style nil)πŸ”š

✳(def metadata {:title "Putting text into columns with extended forms"
:page-style page-style})πŸ”š
:page-style
(garden/css
(list
(at-import "https://fonts.googleapis.com/css2?family=Zen+Kaku+Gothic+New:wght@300;400;500;700;900&display=swap")
[:body {:font-family "'Zen Kaku Gothic New', sans-serif"
:max-width "60ch"}]
[:h1 {:font-size "3rem"
:font-weight "900"
:max-width "90ch"}]
[:.cols-2 {:display "flex"}]
[:.col {:flex "50%"}]
))
#_page-style})πŸ”š

✳=[:h1 (:title metadata)]πŸ”š

Expand Down
48 changes: 25 additions & 23 deletions pages/fab.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
[site.fabricate.prototype.page :refer :all]
[garden.stylesheet :as stylesheet])) πŸ”š

✳ (def page-css
✳ (def page-css nil) πŸ”š

✳ (def metadata
{:title "Introduction"
:page-style
(garden/css
(garden.stylesheet/at-import "https://fonts.googleapis.com/css2?family=Inria+Sans:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&family=Inter:wght@900&display=swap")
[:body {:background-image "linear-gradient(34deg, #9CC0DA, #ECD8D8 45%)"
:font-family "'Inria Sans', sans-serif"
:font-size "22px"}]
[:header {:font-family "Inter"}
[:h1 {:font-size "8rem"
:color "#dc4032"
:line-height "7rem"}]]
[:.red {:color "#FF0000"}]
[:pre {:white-space "pre-wrap"
:font-size "0.95rem"}]
[:.scarlet {:color "#a1010c"}]
[:.vermilion {:color "#dc4032"}]
[:.txt-1999 {:text-transform "uppercase"}]
[:code {:color "#333"}]
[:article {:color "#222"
:max-width "60rem"}]
[:p {:margin-bottom "2rem"}]
)) πŸ”š

✳ (def metadata {:title "Introduction"
:page-style page-css}) πŸ”š
(list
(garden.stylesheet/at-import "https://fonts.googleapis.com/css2?family=Inria+Sans:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&family=Inter:wght@900&display=swap")
[:body {:background-image "linear-gradient(34deg, #9CC0DA, #ECD8D8 45%)"
:font-family "'Inria Sans', sans-serif"
:font-size "22px"}]
[:header {:font-family "Inter"}
[:h1 {:font-size "8rem"
:color "#dc4032"
:line-height "7rem"}]]
[:.red {:color "#FF0000"}]
[:pre {:white-space "pre-wrap"
:font-size "0.95rem"}]
[:.scarlet {:color "#a1010c"}]
[:.vermilion {:color "#dc4032"}]
[:.txt-1999 {:text-transform "uppercase"}]
[:code {:color "#333"}]
[:article {:color "#222"
:max-width "60rem"}]
[:p {:margin-bottom "2rem"}]))
#_page-css}) πŸ”š


✳= [:header [:h1 "fab" [:br] "ri" [:br] "cate"] ] πŸ”š
Expand Down
6 changes: 2 additions & 4 deletions pages/finite-schema-machines.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [site.fabricate.prototype.page :refer :all]
[site.fabricate.prototype.read :as read]
[site.fabricate.prototype.write :as write]
[site.fabricate.styles :as styles]
[site.fabricate.dev.styles :as styles]
[malli.core :as m]
[clojure.repl :as repl]
[garden.core :as garden]
Expand All @@ -12,9 +12,7 @@
{:title "Organizing computation with Finite Schema Machines"
:description "Using precise schemas to map from data states to functions in Clojure."
:page-style
(garden/css
(concat
styles/docs)
(garden/css styles/docs
)}) πŸ”š

✳= [:header [:h1 (:title metadata)]
Expand Down
2 changes: 1 addition & 1 deletion pages/how-to-guides/emacs-setup.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [site.fabricate.prototype.page :as page]
[site.fabricate.prototype.read :as read]
[garden.core :as garden]
[site.fabricate.styles :as styles])) πŸ”š
[site.fabricate.dev.styles :as styles])) πŸ”š

✳(def metadata {:title "Supporting Fabricate's templates in Emacs"
:page-style (garden/css styles/docs)}) πŸ”š
Expand Down
5 changes: 2 additions & 3 deletions pages/index.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
[garden.core :as garden]
[garden.selectors :refer [root]]
[garden.stylesheet :as stylesheet]
[site.fabricate.styles :as styles]
[site.fabricate.dev.styles :as styles]
[site.fabricate.prototype.check]
[site.fabricate.prototype.read]
[site.fabricate.prototype.schema]
[site.fabricate.prototype.fsm]
[site.fabricate.prototype.write]
[site.fabricate.prototype.page])) πŸ”š

✳ (def page-css (garden/css styles/docs)) πŸ”š

✳(def metadata {:title "Fabricate"
:page-style page-css} )πŸ”š
:page-style (garden/css styles/docs)} )πŸ”š

✳= [:div [:h1 {:class "xl-text"} (:title metadata)] [:hr]
[:h4 "Form by art and labor"]]πŸ”š
Expand Down
2 changes: 1 addition & 1 deletion pages/reference/fabricate-fsm.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [site.fabricate.prototype.page :as page]
[garden.core :as garden]
[clojure.string :as str]
[site.fabricate.styles :as styles]
[site.fabricate.dev.styles :as styles]
[site.fabricate.prototype.fsm :as fsm]
[site.fabricate.prototype.schema :as schema]
[site.fabricate.prototype.write :as write]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[site.fabricate.prototype.fsm :as fsm]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles]))πŸ”š
[site.fabricate.dev.styles :as styles]))πŸ”š

✳(def metadata {:title "site.fabricate.prototype.fsm Namespace"
:page-style (garden/css styles/docs)})πŸ”š
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[site.fabricate.prototype.page :as page]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles]))πŸ”š
[site.fabricate.dev.styles :as styles]))πŸ”š

✳(def metadata {:title "site.fabricate.prototype.html Namespace"
:page-style (garden/css styles/docs)})πŸ”š
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[site.fabricate.prototype.page :as page]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles]))πŸ”š
[site.fabricate.dev.styles :as styles]))πŸ”š

✳(def metadata {:title "site.fabricate.prototype.page Namespace"
:page-style (garden/css styles/docs)})πŸ”š
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[site.fabricate.prototype.page :as page]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles])) πŸ”š
[site.fabricate.dev.styles :as styles])) πŸ”š

✳(def metadata {:title "site.fabricate.prototype.read.grammar Namespace"
:page-style (garden/css styles/docs)}) πŸ”š
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[site.fabricate.prototype.page :as page]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles]))πŸ”š
[site.fabricate.dev.styles :as styles]))πŸ”š

✳(def metadata {:title "site.fabricate.prototype.read Namespace"
:page-style (garden/css styles/docs)})πŸ”š
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[site.fabricate.prototype.schema :as schema]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles]))πŸ”š
[site.fabricate.dev.styles :as styles]))πŸ”š

✳(def metadata {:title "site.fabricate.prototype.schema Namespace"
:page-style (garden/css styles/docs)})πŸ”š
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[site.fabricate.prototype.page :as page]
[malli.core :as m]
[garden.core :as garden]
[site.fabricate.styles :as styles]))πŸ”š
[site.fabricate.dev.styles :as styles]))πŸ”š

✳(def metadata {:title "site.fabricate.prototype.write Namespace"
:page-style (garden/css styles/docs)})πŸ”š
Expand Down
2 changes: 1 addition & 1 deletion pages/reference/template-structure.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[site.fabricate.prototype.read.grammar :as grammar]
[garden.core :as garden]
[garden.stylesheet :as stylesheet]
[site.fabricate.styles :as styles]
[site.fabricate.dev.styles :as styles]
[site.fabricate.prototype.page :as page])) πŸ”š

✳(def metadata {:title "A Reference to Fabricate's Page Templates"
Expand Down
2 changes: 1 addition & 1 deletion pages/tutorials/fabricate-for-docs.html.fab
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require
[clojure.string :as str]
[site.fabricate.prototype.read.grammar :as grammar]
[site.fabricate.styles :as styles]
[site.fabricate.dev.styles :as styles]
[garden.core :as garden]
[garden.selectors :as select]
[garden.stylesheet :as stylesheet]
Expand Down
Loading

0 comments on commit af78a21

Please sign in to comment.