mirror of https://github.com/status-im/reagent.git
More cleanup
This commit is contained in:
parent
573a51bc67
commit
b54b1b0957
|
@ -96,7 +96,7 @@
|
||||||
(when (and page (not html5) (empty? (.getToken history)))
|
(when (and page (not html5) (empty? (.getToken history)))
|
||||||
(dispatch [:set-page page])))))
|
(dispatch [:set-page page])))))
|
||||||
|
|
||||||
(defn as-relative [f]
|
(defn to-relative [f]
|
||||||
(string/replace f #"^/" ""))
|
(string/replace f #"^/" ""))
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
|
|
||||||
(defn link [props child]
|
(defn link [props child]
|
||||||
[:a (assoc props
|
[:a (assoc props
|
||||||
:href (-> props :href as-relative)
|
:href (-> props :href to-relative)
|
||||||
:on-click #(do (.preventDefault %)
|
:on-click #(do (.preventDefault %)
|
||||||
(dispatch [:goto-page (:href props)])))
|
(dispatch [:goto-page (:href props)])))
|
||||||
child])
|
child])
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
;;; Static site generation
|
;;; Static site generation
|
||||||
|
|
||||||
(defn prefix [href page]
|
(defn prefix [href page]
|
||||||
(let [depth (-> #"/" (re-seq (as-relative page)) count)]
|
(let [depth (-> #"/" (re-seq (to-relative page)) count)]
|
||||||
(str (->> "../" (repeat depth) (apply str)) href)))
|
(str (->> "../" (repeat depth) (apply str)) href)))
|
||||||
|
|
||||||
(defn danger [t s]
|
(defn danger [t s]
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
[:body
|
[:body
|
||||||
[:div {:id main-div} (danger :div body-html)]
|
[:div {:id main-div} (danger :div body-html)]
|
||||||
(danger :script (str "var pageConfig = "
|
(danger :script (str "var pageConfig = "
|
||||||
(-> page-conf clj->js js/JSON.stringify)))
|
(-> page-conf clj->js js/JSON.stringify) ";"))
|
||||||
[:script {:src main :type "text/javascript"}]]])))
|
[:script {:src main :type "text/javascript"}]]])))
|
||||||
|
|
||||||
(defn gen-page [page-name conf]
|
(defn gen-page [page-name conf]
|
||||||
|
@ -172,12 +172,12 @@
|
||||||
(defn path-join [& paths]
|
(defn path-join [& paths]
|
||||||
(apply (.' (js/require "path") :join) paths))
|
(apply (.' (js/require "path") :join) paths))
|
||||||
|
|
||||||
(defn read-css [{cssfiles :css-infiles}]
|
(defn read-files [files]
|
||||||
(string/join "\n" (map read-file cssfiles)))
|
(string/join "\n" (map read-file files)))
|
||||||
|
|
||||||
(defn write-resources [dir {file :css-file :as conf}]
|
(defn write-resources [dir {:keys [css-file css-infiles]}]
|
||||||
(write-file (path-join dir file)
|
(write-file (path-join dir css-file)
|
||||||
(read-css conf)))
|
(read-files css-infiles)))
|
||||||
|
|
||||||
|
|
||||||
;;; Main entry points
|
;;; Main entry points
|
||||||
|
@ -185,10 +185,10 @@
|
||||||
(defn ^:export genpages [opts]
|
(defn ^:export genpages [opts]
|
||||||
(log "Generating site")
|
(log "Generating site")
|
||||||
(swap! config merge (js->clj opts :keywordize-keys true))
|
(swap! config merge (js->clj opts :keywordize-keys true))
|
||||||
(let [{:keys [site-dir pages] :as conf} @config
|
(let [{:keys [site-dir pages] :as state} @config
|
||||||
conf (assoc conf :timestamp (str "?" (js/Date.now)))]
|
conf (assoc state :timestamp (str "?" (js/Date.now)))]
|
||||||
(doseq [f pages]
|
(doseq [f pages]
|
||||||
(write-file (path-join site-dir (as-relative f))
|
(write-file (->> f to-relative (path-join site-dir))
|
||||||
(gen-page f conf)))
|
(gen-page f conf)))
|
||||||
(write-resources site-dir conf))
|
(write-resources site-dir conf))
|
||||||
(log "Wrote site"))
|
(log "Wrote site"))
|
||||||
|
|
Loading…
Reference in New Issue