elm-pages-v3-beta/plugins/Cloudinary.elm

76 lines
1.6 KiB
Elm
Raw Normal View History

module Cloudinary exposing (url, urlSquare)
2020-10-21 21:17:10 +03:00
import MimeType
import Pages.Url
2020-10-21 21:17:10 +03:00
url :
String
-> Maybe MimeType.MimeImage
-> Int
-> Pages.Url.Url
2020-10-21 21:17:10 +03:00
url asset format width =
let
base =
"https://res.cloudinary.com/dillonkearns/image/upload"
fetch_format =
case format of
Just MimeType.Png ->
"png"
Just (MimeType.OtherImage "webp") ->
"webp"
Just _ ->
"auto"
Nothing ->
"auto"
transforms =
[ "c_pad"
, "w_" ++ String.fromInt width
, "q_auto"
, "f_" ++ fetch_format
]
|> String.join ","
in
Pages.Url.external (base ++ "/" ++ transforms ++ "/" ++ asset)
urlSquare :
String
-> Maybe MimeType.MimeImage
-> Int
-> Pages.Url.Url
urlSquare asset format width =
2020-10-21 21:17:10 +03:00
let
base =
"https://res.cloudinary.com/dillonkearns/image/upload"
fetch_format =
case format of
Just MimeType.Png ->
"png"
Just (MimeType.OtherImage "webp") ->
"webp"
Just _ ->
"auto"
Nothing ->
"auto"
transforms =
[ "c_pad"
, "w_" ++ String.fromInt width
, "h_" ++ String.fromInt width
, "q_auto"
, "f_" ++ fetch_format
]
|> String.join ","
in
Pages.Url.external (base ++ "/" ++ transforms ++ "/" ++ asset)