Skip to content

Commit

Permalink
Update status page to use statuspage.io, retinize assets
Browse files Browse the repository at this point in the history
@StatusPage have kindly donated an account to Clojars. This commit adds
a link to their hosted status page, and their logo to the footer.

It also adds helper functions to generate img tags which support srcset
so that we can server retina images to capable devices.
  • Loading branch information
danielcompton committed Jan 13, 2016
1 parent 8abce6f commit a022057
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 3 deletions.
Empty file added dev-resources/public/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added dev-resources/public/img2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added dev-resources/public/img3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Binary file added resources/public/images/statuspage-io-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/public/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/public/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions src/clojars/web/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
(:require [hiccup.core :refer [html]]
[hiccup.page :refer [include-css include-js]]
[hiccup.element :refer [link-to unordered-list image]]
[clojars.web.safe-hiccup :refer [html5 raw form-to]]))
[clojars.web.safe-hiccup :refer [html5 raw form-to]]
[clojars.web.helpers :as helpers]
[clojure.string :refer [join]]
[clojure.java.io :as io]))

(defn when-ie [& contents]
(str
Expand All @@ -13,6 +16,7 @@
(def footer
[:footer.row
(link-to "https://github.com/clojars/clojars-web/wiki/About" "about")
(link-to "http://status.clojars.org" "status")
(link-to "/projects" "projects")
(link-to "https://github.com/clojars/clojars-web/wiki/Contributing" "contribute")
(link-to "https://groups.google.com/forum/?fromgroups#!topicsearchin/clojars-maintainers/group:clojars-maintainers$20AND$20subject:ann" "news")
Expand Down Expand Up @@ -42,12 +46,19 @@
"https://dnsimple.link/resolving-clojars"
[:span "resolving with" [:br]]
[:span
(image "https://cdn.dnsimple.com/assets/resolving-with-us/logo-light.png" "DNSimple")])]]]]]
(image "https://cdn.dnsimple.com/assets/resolving-with-us/logo-light.png" "DNSimple")])]]
[:tr
[:td.sponsor]
[:td.sponsor
(link-to {:target "_blank"}
"https://www.statuspage.io"
(helpers/retinized-image "/images/statuspage-io-logo.png" "StatusPage.io"))]
[:td.sponsor]]]]]
[:div.row.sponsors
"remixed by"
(link-to {:target "_blank"}
"http://www.bendyworks.com/"
(image "/images/bendyworks_logo_white.png" "Bendyworks Inc."))]])
(image "/images/bendyworks-logo.svg" "Bendyworks Inc."))]])

(defn google-analytics-js []
[:script "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down
40 changes: 40 additions & 0 deletions src/clojars/web/helpers.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(ns clojars.web.helpers
(:require [clojure.java.io :as io]
[clojure.string :as str]))

(defn public-resource-exists?
"Takes a path and checks whether the resource exists under the public directory
at that path."
[path]
(some-> (str "public" path)
(io/resource)
(io/file)
(.exists)))

(defn srcset-part
"Creates a srcset part, e.g.
\"images/[email protected] 2x\"
Returns nil if the file referenced does not exist"
[base extension scale]
(let [retina-path (str base "@" scale extension)]
(when (and retina-path (public-resource-exists? retina-path))
(str retina-path " " scale))))

(defn retinized-image
"Creates an img tag with support for 2x and 3x retina images.
Will check if the retina images exist before adding them to srcset.
Throws if the src image does not exist."
[src alt]
(assert (= (first src) \/) (format "src %s must start with a /" src))
(assert (public-resource-exists? src)
(format "File %s does not exist" (str "public" src)))

(let [last-period (.lastIndexOf src ".")
base (.substring src 0 last-period)
extension (.substring src last-period (count src))]
[:img {:src src
:alt alt
;; If 1x is not provided in srcset, then browsers will default to src as the 1x image
:srcset (->> (filter identity [(srcset-part base extension "2x")
(srcset-part base extension "3x")])
(str/join ", "))}]))
33 changes: 33 additions & 0 deletions test/clojars/test/unit/web/helpers.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ns clojars.test.unit.web.helpers
(require [clojure.test :refer :all]
[clojars.web.helpers :as helpers]))

(deftest resource-exists?
(is (helpers/public-resource-exists? "/test-resource"))
(is (not (helpers/public-resource-exists? "/nonexistent-resource"))))

(deftest srcset-part
(is (= "/[email protected] 2x"
(helpers/srcset-part "/img1" ".png" "2x")))
(is (= "/[email protected] 3x"
(helpers/srcset-part "/img1" ".png" "3x")))
(is (nil? (helpers/srcset-part "/img2" ".png" "2x"))))

(deftest retinized-imaged
(is (= [:img
{:alt "Image 1"
:src "/img1.png"
:srcset "/[email protected] 2x, /[email protected] 3x"}]
(helpers/retinized-image "/img1.png" "Image 1")))
(is (= [:img
{:alt "Image 2"
:src "/img2.png"
:srcset "/[email protected] 3x"}]
(helpers/retinized-image "/img2.png" "Image 2")))
(is (= [:img
{:alt "Image 3"
:src "/img3.jpeg"
:srcset ""}]
(helpers/retinized-image "/img3.jpeg" "Image 3")))
(is (thrown? AssertionError (helpers/retinized-image "/img-not-exist.png" "Nope")))
(is (thrown? AssertionError (helpers/retinized-image "img1.png" "Image 1"))))

0 comments on commit a022057

Please sign in to comment.