mirror of https://github.com/status-im/reagent.git
Fix site-generation and simplify title setting
This commit is contained in:
parent
bffbae231d
commit
bc89612a76
3
Makefile
3
Makefile
|
@ -46,7 +46,8 @@ serve-site: trigger-build
|
|||
trigger-build:
|
||||
# always trigger build to make sure page-generation works
|
||||
@echo "(ns empty.generated.ns)" > demo/empty.cljs
|
||||
cat examples/todomvc/todos.css examples/simple/example.css \
|
||||
@(echo "/* Generated, do not modify */\n\n" && \
|
||||
cat examples/todomvc/todos.css examples/simple/example.css) \
|
||||
> site/public/css/examples.css
|
||||
|
||||
|
||||
|
|
|
@ -24,11 +24,14 @@
|
|||
(def index-page "index.html")
|
||||
(def news-page "news/index.html")
|
||||
|
||||
(tools/register-page index-page (fn [] [intro/main]))
|
||||
(tools/register-page news-page (fn [] [news/main]))
|
||||
(tools/register-page index-page
|
||||
(fn [] [intro/main])
|
||||
"Reagent: Minimalistic React for ClojureScript")
|
||||
(tools/register-page news-page
|
||||
(fn [] [news/main])
|
||||
"Reagent news")
|
||||
|
||||
(defn demo []
|
||||
(dbg "demo")
|
||||
[:div
|
||||
[:div.nav
|
||||
[:ul.nav
|
||||
|
@ -43,4 +46,6 @@
|
|||
|
||||
(defn start! [{:keys [test-results]}]
|
||||
(reset! test-results-comp test-results)
|
||||
(tools/start! {:body (fn [] [demo])}))
|
||||
(tools/start! {:body (fn [] [demo])
|
||||
:css-infiles ["site/public/css/main.css"
|
||||
"site/public/css/examples.css"]}))
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[reagent.debug :refer-macros [dbg println]]
|
||||
[clojure.string :as string]
|
||||
[reagentdemo.syntax :refer-macros [get-source]]
|
||||
[sitetools :refer [link title]]
|
||||
[sitetools :refer [link]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]
|
||||
[simpleexample :as simple]
|
||||
[todomvc :as todo]))
|
||||
|
@ -323,7 +323,6 @@
|
|||
(js/setTimeout #(reset! show-all true) 500)
|
||||
(fn []
|
||||
[:div.reagent-demo
|
||||
[title head]
|
||||
[:h1 head]
|
||||
[intro]
|
||||
[managing-state]
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]
|
||||
[sitetools :as tools :refer [title link]]
|
||||
[sitetools :as tools :refer [link]]
|
||||
[reagentdemo.news.anyargs :as anyargs]
|
||||
[reagentdemo.news.async :as async]
|
||||
[reagentdemo.news.undodemo :as undodemo]
|
||||
|
@ -11,7 +11,6 @@
|
|||
|
||||
(defn main []
|
||||
[:div
|
||||
[title "Reagent news"]
|
||||
[clock/main {:summary true}]
|
||||
[anyargs/main {:summary true}]
|
||||
[async/main {:summary true}]
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :refer-macros [get-source]]
|
||||
[sitetools :as tools :refer [title link]]
|
||||
[sitetools :as tools :refer [link]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]
|
||||
[geometry.core :as geometry]))
|
||||
|
||||
(def url "news/any-arguments.html")
|
||||
(def title "All arguments allowed")
|
||||
|
||||
(def funmap (-> ::this get-source common/fun-map))
|
||||
(def src-for (partial common/src-for funmap))
|
||||
|
@ -33,12 +34,10 @@
|
|||
[:p "Some other text in bold."]]])
|
||||
|
||||
(defn main [{:keys [summary]}]
|
||||
(let [head "All arguments allowed"
|
||||
geometry {:href "https://github.com/reagent-project/reagent/tree/master/examples/geometry"}
|
||||
(let [geometry {:href "https://github.com/reagent-project/reagent/tree/master/examples/geometry"}
|
||||
jonase {:href "https://github.com/jonase"}]
|
||||
[:div.reagent-demo
|
||||
[:h1 [link {:href url} head]]
|
||||
[title (str "Reagent 0.4.0: " head)]
|
||||
[:h1 [link {:href url} title]]
|
||||
[:div.demo-text
|
||||
|
||||
[:h2 "If it looks like a function…"]
|
||||
|
@ -132,4 +131,5 @@
|
|||
|
||||
[demo-component {:comp geometry-example}]])]]))
|
||||
|
||||
(tools/register-page url (fn [] [main]))
|
||||
(tools/register-page url (fn [] [main])
|
||||
(str "Reagent: " title))
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :refer-macros [get-source]]
|
||||
[sitetools :as tools :refer [title link]]
|
||||
[sitetools :as tools :refer [link]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]))
|
||||
|
||||
(def url "news/reagent-is-async.html")
|
||||
(def title "Faster by waiting")
|
||||
|
||||
(def funmap (-> "reagentdemo/news/async.cljs" get-source common/fun-map))
|
||||
(def src-for (partial common/src-for funmap))
|
||||
|
@ -93,8 +94,7 @@
|
|||
(defn main [{:keys [summary]}]
|
||||
(let [om-article {:href "http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/"}]
|
||||
[:div.reagent-demo
|
||||
[title "Reagent: Faster by waiting"]
|
||||
[:h1 [link {:href url} "Faster by waiting"]]
|
||||
[:h1 [link {:href url} title]]
|
||||
[:div.demo-text
|
||||
[:h2 "Reagent gets async rendering"]
|
||||
|
||||
|
@ -196,4 +196,5 @@
|
|||
:reset-random-colors :color-choose :ncolors-choose
|
||||
:palette :color-demo])}]])]]))
|
||||
|
||||
(tools/register-page url (fn [] [main]))
|
||||
(tools/register-page url (fn [] [main])
|
||||
(str "Reagent: " title))
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg]]
|
||||
[reagentdemo.syntax :refer-macros [get-source]]
|
||||
[sitetools :as tools :refer [title link]]
|
||||
[sitetools :as tools :refer [link]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]
|
||||
[reagentdemo.news.binaryclock :as binaryclock]))
|
||||
|
||||
(def url "news/binary-clock.html")
|
||||
(def title "A binary clock")
|
||||
|
||||
(def funmap (-> "reagentdemo/news/binaryclock.cljs"
|
||||
get-source common/fun-map))
|
||||
|
@ -18,16 +19,14 @@
|
|||
:no-heading true}])
|
||||
|
||||
(defn main [{:keys [summary]}]
|
||||
(let [head "A binary clock"
|
||||
lexclock {:href "http://www.lexicallyscoped.com/2014/01/23/clojurescript-react-om-binary-clock.html"}
|
||||
(let [lexclock {:href "http://www.lexicallyscoped.com/2014/01/23/clojurescript-react-om-binary-clock.html"}
|
||||
hopclock {:href "http://pmbauer.github.io/2014/01/27/hoplon-binary-clock/"}
|
||||
om {:href "https://github.com/swannodette/om"}
|
||||
hoplon {:href "http://hoplon.io"}
|
||||
clocksrc {:href "https://github.com/reagent-project/reagent/blob/master/demo/reagentdemo/news/binaryclock.cljs"}]
|
||||
|
||||
[:div.reagent-demo
|
||||
[:h1 [link {:href url} head]]
|
||||
[title head]
|
||||
[:h1 [link {:href url} title]]
|
||||
[:div.demo-text
|
||||
|
||||
(when-not summary
|
||||
|
@ -121,4 +120,5 @@
|
|||
description that corresponds to those arguments, and leave it
|
||||
to React to actually display that UI."]])]]))
|
||||
|
||||
(tools/register-page url (fn [] [main]))
|
||||
(tools/register-page url (fn [] [main])
|
||||
(str "Reagent: " title))
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :refer-macros [get-source]]
|
||||
[sitetools :as tools :refer [title link]]
|
||||
[sitetools :as tools :refer [link]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]
|
||||
[todomvc :as todomvc]))
|
||||
|
||||
(def url "news/cloact-reagent-undo-demo.html")
|
||||
(def title "Cloact becomes Reagent: Undo is trivial")
|
||||
|
||||
(def funmap (-> ::this get-source common/fun-map))
|
||||
(def src-for (partial common/src-for funmap))
|
||||
|
@ -48,10 +49,9 @@
|
|||
(remove-watch state ::undo-watcher))}))
|
||||
|
||||
(defn main [{:keys [summary]}]
|
||||
(let [head "Cloact becomes Reagent: Undo is trivial"]
|
||||
(let [head title]
|
||||
[:div.reagent-demo
|
||||
[:h1 [link {:href url} head]]
|
||||
[title head]
|
||||
[:div.demo-text
|
||||
[:h2 "(reset! cloact-name \"Reagent\")"]
|
||||
|
||||
|
@ -88,4 +88,4 @@
|
|||
|
||||
[undo-demo-cleanup]])]]))
|
||||
|
||||
(tools/register-page url (fn [] [main]))
|
||||
(tools/register-page url (fn [] [main]) title)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
(defonce config (atom {:page-map {"index.html"
|
||||
(fn [] [:div "Empty"])}
|
||||
:page-titles {}
|
||||
:body (fn [] [:div (page-content)])
|
||||
:site-dir "outsite/public"
|
||||
:css-infiles ["site/public/css/main.css"]
|
||||
|
@ -31,14 +32,19 @@
|
|||
:allow-html5-history false}))
|
||||
|
||||
(defonce page (atom "index.html"))
|
||||
(defonce page-title (atom (:default-title @config)))
|
||||
(defonce page-state (atom {:has-history false}))
|
||||
|
||||
(defn register-page [pageurl comp]
|
||||
(assert (string? pageurl) (str "expected string, not " pageurl))
|
||||
(defn register-page
|
||||
([pageurl comp]
|
||||
(register-page pageurl comp nil))
|
||||
([pageurl comp title]
|
||||
(assert (string? pageurl)
|
||||
(str "expected string, not " pageurl))
|
||||
(assert (fn? comp))
|
||||
(swap! config update-in [:page-map] assoc pageurl comp))
|
||||
|
||||
(assert (or (nil? title)
|
||||
(string? title)))
|
||||
(swap! config update-in [:page-map] assoc pageurl comp)
|
||||
(swap! config update-in [:page-titles] assoc pageurl title)))
|
||||
|
||||
|
||||
;;; Components
|
||||
|
@ -61,14 +67,6 @@
|
|||
identity))
|
||||
child]))
|
||||
|
||||
(defn title [name]
|
||||
(when (= @page-title "")
|
||||
;; First title on a page wins
|
||||
(reset! page-title name)
|
||||
(when reagent/is-client
|
||||
(set! (.-title js/document) @page-title)))
|
||||
nil)
|
||||
|
||||
(defn page-content []
|
||||
[(get-in @config [:page-map @page]
|
||||
(get-in @config [:page-map "index.html"]))])
|
||||
|
@ -78,13 +76,19 @@
|
|||
|
||||
;;; Implementation:
|
||||
|
||||
(defn get-title []
|
||||
(get-in @config [:page-titles @page]
|
||||
(:default-title @config)))
|
||||
|
||||
(defn default-content []
|
||||
[:div "Empty"])
|
||||
|
||||
(add-watch page ::title-watch
|
||||
(fn [_ _ _ p]
|
||||
(when reagent/is-client
|
||||
(set! (.-title js/document) (get-title)))
|
||||
;; First title on a page wins
|
||||
(reset! page-title "")))
|
||||
#_(reset! page-title "")))
|
||||
|
||||
;;; History
|
||||
|
||||
|
@ -185,7 +189,7 @@
|
|||
(reset! page page-name)
|
||||
(let [b (reagent/render-component-to-string (body))]
|
||||
(str "<!doctype html>"
|
||||
(html-template {:title @page-title
|
||||
(html-template {:title (get-title)
|
||||
:body b
|
||||
:page-conf {:allow-html5-history true
|
||||
:page-name page-name}
|
||||
|
@ -255,5 +259,6 @@
|
|||
(set-start-page page-name))
|
||||
(swap! config merge conf)
|
||||
(setup-history)
|
||||
(set! (.-title js/document) (get-title))
|
||||
(reagent/render-component (body)
|
||||
(.' js/document :body)))))
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
:output-dir
|
||||
"outsite/public/js/out"}}}}}
|
||||
|
||||
:site {:resource-paths ^:replace ["outsite"]
|
||||
:site {:resource-paths ^:replace ["outsite" "vendor"]
|
||||
:figwheel {:css-dirs ^:replace ["outsite/public/css"]}
|
||||
:cljsbuild {:builds
|
||||
{:client
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
/* Generated, do not modify */
|
||||
|
||||
|
||||
@charset "utf-8";
|
||||
html,
|
||||
body {
|
||||
|
|
Loading…
Reference in New Issue