Skip to content

Instantly share code, notes, and snippets.

@deciduously
Forked from sritchie/optimus.clj
Created January 10, 2018 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deciduously/e77ab5007d15c3e30eb6e747d6f9b260 to your computer and use it in GitHub Desktop.
Save deciduously/e77ab5007d15c3e30eb6e747d6f9b260 to your computer and use it in GitHub Desktop.
(defn optify
"Helper that examines paths with the supplied prefix and either subs
in their cache-busting URLs or returns them unchanged."
[req prefix]
(fn [^String src]
(or (and (.startsWith src prefix)
(not-empty (link/file-path req src)))
src)))
;; Any html transformation you pass in via `main` gets its img tags rewritten with no extra work!
(deftemplate base-layout
base-template
[request main]
[:head :link] #(update-in % [:attrs :href] (optify request "/img/")) ;; for favicon.ico
[:.main] main
[:img] #(update-in % [:attrs :src] (optify request "/img/"))
[:div#google-analytics] (if-let [code (conf/get-config :analytics)]
(append (google-analytics code))
identity))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment