Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created December 4, 2013 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save sritchie/7794646 to your computer and use it in GitHub Desktop.
Save sritchie/7794646 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