-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update status page to use statuspage.io, retinize assets
@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
1 parent
8abce6f
commit a022057
Showing
13 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ", "))}])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")))) |