Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
(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)))
;; Any html transformation you pass in via `main` gets its img tags rewritten with no extra work!
(deftemplate base-layout
[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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment