Skip to content

Commit

Permalink
feat(performance): redirect to resized images
Browse files Browse the repository at this point in the history
  • Loading branch information
luhmann committed Mar 22, 2018
1 parent 6f643ad commit 0968d16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Beer.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ let make =
switch image {
| None => ReasonReact.nullElement
| Some(img_url) =>
let url =
Utils.getFilename(img_url)
|> Js.Option.getWithDefault(img_url)
|> Utils.generateImgUrl;
<div
className="bg-contain bg-top bg-no-repeat h-48 sm:h-auto beerImg-width test-beer-card-img"
style=(
ReactDOMRe.Style.make(~backgroundImage={j|url($img_url)|j}, ())
)
/>
style=(ReactDOMRe.Style.make(~backgroundImage={j|url($url)|j}, ()))
/>;
};
<div
className="shadow-lg rounded mb-4 overflow-hidden max-w-md p-3 sm:flex test-beer-card">
Expand Down
12 changes: 12 additions & 0 deletions src/Utils.re
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,15 @@ let logError = err => {

[@bs.scope ("window", "location")] [@bs.val]
external basePath : string = "pathname";

let getFilename = url =>
Js.String.split("/", url)
|> Js.Array.pop
|> Js.Option.getWithDefault("")
|> Js.String.split(".")
|> Js.Array.shift;

let generateImgUrl = filename =>
"https://s3.eu-central-1.amazonaws.com/punk-api-images/resized/"
++ filename
++ ".jpg";

0 comments on commit 0968d16

Please sign in to comment.