mirror of
https://github.com/status-im/reagent.git
synced 2025-02-05 00:23:48 +00:00
Use md5 hash for demo site cache busting instead of build timestamp
This commit is contained in:
parent
1ebe5e978b
commit
fddedf4143
@ -6,7 +6,7 @@ SHA=$(git rev-parse HEAD)
|
|||||||
|
|
||||||
lein 'do' clean, cljsbuild once prod-npm, cljsbuild once prerender
|
lein 'do' clean, cljsbuild once prod-npm, cljsbuild once prerender
|
||||||
|
|
||||||
node target/cljsbuild/prerender/main.js
|
node target/cljsbuild/prerender/main.js target/prod-npm/public/
|
||||||
|
|
||||||
lein codox
|
lein codox
|
||||||
|
|
||||||
|
@ -2,18 +2,18 @@
|
|||||||
(:require [reagent.debug :refer-macros [log]]
|
(:require [reagent.debug :refer-macros [log]]
|
||||||
[sitetools.core :as tools]
|
[sitetools.core :as tools]
|
||||||
[sitetools.server :as server]
|
[sitetools.server :as server]
|
||||||
[reagentdemo.core :as demo]))
|
[reagentdemo.core :as demo]
|
||||||
|
[path :as path]))
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
(log "Generating site")
|
(log "Generating site")
|
||||||
(demo/init!)
|
(demo/init!)
|
||||||
(let [conf @tools/config
|
(let [[js-resource-path] args
|
||||||
conf (assoc conf :timestamp (str "?" (js/Date.now)))
|
{:keys [site-dir pages] :as conf} (assoc @tools/config :js-resource-path js-resource-path)]
|
||||||
{:keys [site-dir pages]} conf]
|
(server/write-resources site-dir conf)
|
||||||
(doseq [f (keys pages)]
|
(doseq [f (keys pages)]
|
||||||
(server/write-file (->> f tools/to-relative (server/path-join site-dir))
|
(server/write-file (->> f tools/to-relative (path/join site-dir))
|
||||||
(server/gen-page f conf)))
|
(server/gen-page f conf))))
|
||||||
(server/write-resources site-dir conf))
|
|
||||||
(log "Wrote site")
|
(log "Wrote site")
|
||||||
(js/process.exit 0))
|
(js/process.exit 0))
|
||||||
|
|
||||||
|
@ -6,7 +6,11 @@
|
|||||||
[reagent.dom.server :as server]
|
[reagent.dom.server :as server]
|
||||||
[reagent.debug :refer-macros [dbg log dev?]]
|
[reagent.debug :refer-macros [dbg log dev?]]
|
||||||
[reagent.interop :as i :refer-macros [$ $!]]
|
[reagent.interop :as i :refer-macros [$ $!]]
|
||||||
[sitetools.core :as tools]))
|
[sitetools.core :as tools]
|
||||||
|
[md5-file :as md5-file]
|
||||||
|
[path :as path]
|
||||||
|
[fs :as fs]
|
||||||
|
[path :as path]))
|
||||||
|
|
||||||
|
|
||||||
;;; Static site generation
|
;;; Static site generation
|
||||||
@ -18,23 +22,31 @@
|
|||||||
(defn danger [t s]
|
(defn danger [t s]
|
||||||
[t {:dangerouslySetInnerHTML {:__html s}}])
|
[t {:dangerouslySetInnerHTML {:__html s}}])
|
||||||
|
|
||||||
(defn html-template [{:keys [title body-html timestamp page-conf
|
(defn add-cache-buster [resource-path path]
|
||||||
js-file css-file main-div]}]
|
(let [h (md5-file/sync (path/join resource-path path))]
|
||||||
(let [main (str js-file timestamp)]
|
(str path "?" (subs h 0 6))))
|
||||||
(server/render-to-static-markup
|
|
||||||
[:html
|
(defn html-template [{:keys [title body-html page-conf
|
||||||
[:head
|
js-file css-file main-div
|
||||||
[:meta {:charset 'utf-8}]
|
js-resource-path site-dir]}]
|
||||||
[:meta {:name 'viewport
|
(server/render-to-static-markup
|
||||||
:content "width=device-width, initial-scale=1.0"}]
|
[:html
|
||||||
[:base {:href (-> page-conf :page-path base)}]
|
[:head
|
||||||
[:link {:href (str css-file timestamp) :rel 'stylesheet}]
|
[:meta {:charset 'utf-8}]
|
||||||
[:title title]]
|
[:meta {:name 'viewport
|
||||||
[:body
|
:content "width=device-width, initial-scale=1.0"}]
|
||||||
[:div {:id main-div} (danger :div body-html)]
|
[:base {:href (-> page-conf :page-path base)}]
|
||||||
(danger :script (str "var pageConfig = "
|
[:link {:href (add-cache-buster site-dir css-file)
|
||||||
(-> page-conf clj->js js/JSON.stringify)))
|
:rel "stylesheet"}]
|
||||||
[:script {:src main :type "text/javascript"}]]])))
|
[:title title]]
|
||||||
|
[:body
|
||||||
|
[:div
|
||||||
|
{:id main-div}
|
||||||
|
(danger :div body-html)]
|
||||||
|
(danger :script (str "var pageConfig = "
|
||||||
|
(-> page-conf clj->js js/JSON.stringify)))
|
||||||
|
[:script {:src (add-cache-buster js-resource-path js-file)
|
||||||
|
:type "text/javascript"}]]]))
|
||||||
|
|
||||||
(defn gen-page [page-path conf]
|
(defn gen-page [page-path conf]
|
||||||
(tools/emit [:set-page page-path])
|
(tools/emit [:set-page page-path])
|
||||||
@ -46,26 +58,20 @@
|
|||||||
:page-conf {:page-path page-path}
|
:page-conf {:page-path page-path}
|
||||||
:body-html bhtml)))))
|
:body-html bhtml)))))
|
||||||
|
|
||||||
(defn fs [] (js/require "fs"))
|
|
||||||
(defn path [] (js/require "path"))
|
|
||||||
|
|
||||||
(defn mkdirs [f]
|
(defn mkdirs [f]
|
||||||
(doseq [d (reductions #(str %1 "/" %2)
|
(doseq [d (reductions #(str %1 "/" %2)
|
||||||
(-> ($ (path) normalize f)
|
(-> (path/normalize f)
|
||||||
(string/split #"/")))]
|
(string/split #"/")))]
|
||||||
(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]
|
||||||
(log "Write" f)
|
(log "Write" f)
|
||||||
(mkdirs ($ (path) dirname f))
|
(mkdirs (path/dirname f))
|
||||||
($ (fs) writeFileSync f content))
|
(fs/writeFileSync f content))
|
||||||
|
|
||||||
(defn path-join [& paths]
|
|
||||||
(apply ($ (path) :join) paths))
|
|
||||||
|
|
||||||
(defn write-resources [dir {:keys [css-file css-infiles]}]
|
(defn write-resources [dir {:keys [css-file css-infiles]}]
|
||||||
(write-file (path-join dir css-file)
|
(write-file (path/join dir css-file)
|
||||||
(->> css-infiles
|
(->> css-infiles
|
||||||
(map #($ (fs) readFileSync %))
|
(map #(fs/readFileSync %))
|
||||||
(string/join "\n"))))
|
(string/join "\n"))))
|
||||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -3922,6 +3922,12 @@
|
|||||||
"integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=",
|
"integrity": "sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"md5-file": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/md5-file/-/md5-file-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-UC0qFwyAjn4YdPpKaDNw6gNxRf7Mcx7jC1UGCY4boCzgvU2Aoc1mOGzTtrjjLKhM5ivsnhoKpQVxKPp+1j1qwg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"md5.js": {
|
"md5.js": {
|
||||||
"version": "1.3.4",
|
"version": "1.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz",
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
"karma": "2.0.0",
|
"karma": "2.0.0",
|
||||||
"karma-chrome-launcher": "2.2.0",
|
"karma-chrome-launcher": "2.2.0",
|
||||||
"karma-cljs-test": "0.1.0",
|
"karma-cljs-test": "0.1.0",
|
||||||
"karma-junit-reporter": "1.2.0"
|
"karma-junit-reporter": "1.2.0",
|
||||||
|
"md5-file": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user