Use cloudinary image for author image.

This commit is contained in:
Dillon Kearns 2020-10-21 11:17:10 -07:00
parent 68b80728fd
commit d00f326f5c
3 changed files with 45 additions and 30 deletions

View File

@ -1,5 +1,6 @@
module Data.Author exposing (Author, all, decoder, view)
import Cloudinary
import Element exposing (Element)
import Html.Attributes as Attr
import Json.Decode as Decode exposing (Decoder)
@ -18,7 +19,7 @@ type alias Author =
all : List Author
all =
[ { name = "Dillon Kearns"
, avatar = Pages.images.author.dillon
, avatar = Cloudinary.url "v1602899672/elm-radio/dillon-profile_n2lqst.jpg" Nothing 140
, bio = "Elm developer and educator. Founder of Incremental Elm Consulting."
}
]

View File

@ -1,5 +1,6 @@
module Main exposing (main)
import Cloudinary
import Color
import Data.Author as Author
import Date
@ -83,35 +84,8 @@ cloudinaryIcon :
MimeType.MimeImage
-> Int
-> ImagePath pathKey
cloudinaryIcon format width =
let
base =
"https://res.cloudinary.com/dillonkearns/image/upload"
asset =
"v1603234028/elm-pages/elm-pages-icon"
fetch_format =
case format of
MimeType.Png ->
"png"
MimeType.OtherImage "webp" ->
"webp"
_ ->
"auto"
transforms =
[ "c_pad"
, "w_" ++ String.fromInt width
, "h_" ++ String.fromInt width
, "q_auto"
, "f_" ++ fetch_format
]
|> String.join ","
in
ImagePath.external (base ++ "/" ++ transforms ++ "/" ++ asset)
cloudinaryIcon mimeType width =
Cloudinary.url "v1603234028/elm-pages/elm-pages-icon" (Just mimeType) width
type alias View =

40
src/Cloudinary.elm Normal file
View File

@ -0,0 +1,40 @@
module Cloudinary exposing (..)
import MimeType
import Pages.ImagePath as ImagePath exposing (ImagePath)
url :
String
-> Maybe MimeType.MimeImage
-> Int
-> ImagePath pathKey
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
, "h_" ++ String.fromInt width
, "q_auto"
, "f_" ++ fetch_format
]
|> String.join ","
in
ImagePath.external (base ++ "/" ++ transforms ++ "/" ++ asset)