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)
|
(str url "?" modification-timestamp)
|
||||||
url))
|
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
|
; defined using the same type of map structure as in clj-jtwig.standard-functions
|
||||||
|
|
||||||
(defonce web-functions
|
(defonce web-functions
|
||||||
|
@ -41,11 +61,14 @@
|
||||||
|
|
||||||
"stylesheet"
|
"stylesheet"
|
||||||
{:fn (fn [url & [media]]
|
{:fn (fn [url & [media]]
|
||||||
(let [fmt (if media
|
(let [fmt (if media
|
||||||
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" media=\"%s\" />"
|
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" media=\"%s\" />"
|
||||||
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" />")]
|
"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\" />")
|
||||||
(format fmt (get-url-string url) media)))}
|
resource-path (get-minified-resource-url url)]
|
||||||
|
(format fmt (get-url-string resource-path) media)))}
|
||||||
|
|
||||||
"javascript"
|
"javascript"
|
||||||
{:fn (fn [url]
|
{: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