update stylesheet/javascript functions with check for minified urls
This commit is contained in:
parent
b633939883
commit
75c8abd7b5
|
@ -32,6 +32,26 @@
|
|||
(str url "?" modification-timestamp)
|
||||
url))
|
||||
|
||||
(defn- minified-url? [url]
|
||||
(re-matches #"^(.+\.)min\.(css|js)$" url))
|
||||
|
||||
(defn- make-minified-url [^String url]
|
||||
(let [pos (.lastIndexOf url (int \.))]
|
||||
(if (> pos -1)
|
||||
(let [name (subs url 0 pos)
|
||||
extension (subs url (inc pos))]
|
||||
(str name ".min." extension))
|
||||
url)))
|
||||
|
||||
(defn- get-minified-resource-url [url]
|
||||
(if (or (not (:check-for-minified-web-resources @options))
|
||||
(minified-url? url))
|
||||
url
|
||||
(let [minified-url (make-minified-url url)]
|
||||
(if (get-resource-path (str root-resource-path minified-url))
|
||||
minified-url
|
||||
url))))
|
||||
|
||||
; defined using the same type of map structure as in clj-jtwig.standard-functions
|
||||
|
||||
(defonce web-functions
|
||||
|
@ -41,11 +61,14 @@
|
|||
|
||||
"stylesheet"
|
||||
{:fn (fn [url & [media]]
|
||||
(let [fmt (if media
|
||||
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" media=\"%s\" />"
|
||||
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" />")]
|
||||
(format fmt (get-url-string url) media)))}
|
||||
(let [fmt (if media
|
||||
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" media=\"%s\" />"
|
||||
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" />")
|
||||
resource-path (get-minified-resource-url url)]
|
||||
(format fmt (get-url-string resource-path) media)))}
|
||||
|
||||
"javascript"
|
||||
{:fn (fn [url]
|
||||
(format "<script type=\"text/javascript\" src=\"%s\"></script>" (get-url-string url)))}})
|
||||
(let [fmt "<script type=\"text/javascript\" src=\"%s\"></script>"
|
||||
resource-path (get-minified-resource-url url)]
|
||||
(format fmt (get-url-string resource-path))))}})
|
||||
|
|
Reference in a new issue