mirror of https://github.com/status-im/reagent.git
Simplify
This commit is contained in:
parent
007de00033
commit
47a0d80a70
|
@ -20,7 +20,7 @@
|
||||||
(do (-> (or a.rswapfs
|
(do (-> (or a.rswapfs
|
||||||
(set! a.rswapfs (array)))
|
(set! a.rswapfs (array)))
|
||||||
(.push #(apply f % args)))
|
(.push #(apply f % args)))
|
||||||
nil)
|
(swap! a identity))
|
||||||
(do (set! a.rswapping true)
|
(do (set! a.rswapping true)
|
||||||
(try (swap! a (fn [state]
|
(try (swap! a (fn [state]
|
||||||
(loop [s (apply f state args)]
|
(loop [s (apply f state args)]
|
||||||
|
@ -86,10 +86,9 @@
|
||||||
|
|
||||||
;;; History
|
;;; History
|
||||||
|
|
||||||
(defn init-history []
|
(defn init-history [page]
|
||||||
(when-not history
|
(when-not history
|
||||||
(let [page (:page-name @config)
|
(let [html5 (and page
|
||||||
html5 (and page
|
|
||||||
(.isSupported Html5History)
|
(.isSupported Html5History)
|
||||||
(#{"http:" "https:"} js/location.protocol))]
|
(#{"http:" "https:"} js/location.protocol))]
|
||||||
(doto (set! history
|
(doto (set! history
|
||||||
|
@ -162,26 +161,26 @@
|
||||||
:page-conf {:page-name page-name}
|
:page-conf {:page-name page-name}
|
||||||
:body-html bhtml)))))
|
:body-html bhtml)))))
|
||||||
|
|
||||||
|
(defn fs [] (js/require "fs"))
|
||||||
|
(defn path [] (js/require "path"))
|
||||||
|
|
||||||
(defn mkdirs [f]
|
(defn mkdirs [f]
|
||||||
(let [fs (js/require "fs")
|
(let [items (as-> f _
|
||||||
path (js/require "path")
|
(.' (path) normalize _)
|
||||||
items (as-> f _
|
|
||||||
(.' path dirname _)
|
|
||||||
(.' path normalize _)
|
|
||||||
(string/split _ #"/"))]
|
(string/split _ #"/"))]
|
||||||
(doseq [d (reductions #(str %1 "/" %2) items)]
|
(doseq [d (reductions #(str %1 "/" %2) items)]
|
||||||
(when-not (.' fs existsSync d)
|
(when-not (.' (fs) existsSync d)
|
||||||
(.' fs mkdirSync d)))))
|
(.' (fs) mkdirSync d)))))
|
||||||
|
|
||||||
(defn write-file [f content]
|
(defn write-file [f content]
|
||||||
(mkdirs f)
|
(mkdirs (.' (path) dirname f))
|
||||||
(.' (js/require "fs") writeFileSync f content))
|
(.' (fs) writeFileSync f content))
|
||||||
|
|
||||||
(defn read-file [f]
|
(defn read-file [f]
|
||||||
(.' (js/require "fs") readFileSync f))
|
(.' (fs) readFileSync f))
|
||||||
|
|
||||||
(defn path-join [& paths]
|
(defn path-join [& paths]
|
||||||
(apply (.' (js/require "path") :join) paths))
|
(apply (.' (path) :join) paths))
|
||||||
|
|
||||||
(defn read-files [files]
|
(defn read-files [files]
|
||||||
(string/join "\n" (map read-file files)))
|
(string/join "\n" (map read-file files)))
|
||||||
|
@ -195,9 +194,9 @@
|
||||||
|
|
||||||
(defn ^:export genpages [opts]
|
(defn ^:export genpages [opts]
|
||||||
(log "Generating site")
|
(log "Generating site")
|
||||||
(swap! config merge (js->clj opts :keywordize-keys true))
|
(let [conf (swap! config merge (js->clj opts :keywordize-keys true))
|
||||||
(let [{:keys [site-dir pages] :as state} @config
|
conf (assoc conf :timestamp (str "?" (js/Date.now)))
|
||||||
conf (assoc state :timestamp (str "?" (js/Date.now)))]
|
{:keys [site-dir pages]} conf]
|
||||||
(doseq [f pages]
|
(doseq [f pages]
|
||||||
(write-file (->> f to-relative (path-join site-dir))
|
(write-file (->> f to-relative (path-join site-dir))
|
||||||
(gen-page f conf)))
|
(gen-page f conf)))
|
||||||
|
@ -207,9 +206,9 @@
|
||||||
(defn start! [site-config]
|
(defn start! [site-config]
|
||||||
(swap! config merge site-config)
|
(swap! config merge site-config)
|
||||||
(when r/is-client
|
(when r/is-client
|
||||||
(let [conf (when (exists? js/pageConfig)
|
(let [page-conf (when (exists? js/pageConfig)
|
||||||
(js->clj js/pageConfig :keywordize-keys true))]
|
(js->clj js/pageConfig :keywordize-keys true))
|
||||||
(swap! config merge conf)
|
conf (swap! config merge page-conf)]
|
||||||
(init-history)
|
(init-history (:page-name conf))
|
||||||
(r/render-component (:body @config)
|
(r/render-component (:body conf)
|
||||||
(js/document.getElementById (:main-div @config))))))
|
(js/document.getElementById (:main-div conf))))))
|
||||||
|
|
Loading…
Reference in New Issue