Serve avatar locally rather than through Libravatar, it'll perform better and doesn't require the image's size to be messed with

This commit is contained in:
Danielle McLean 2017-10-09 23:34:56 +11:00
parent 20470aa852
commit c517baac1c
Signed by: 00dani
GPG Key ID: 5A5D2D1AFF12EEC5
6 changed files with 3 additions and 11 deletions

View File

@ -3,6 +3,7 @@ User
password Text maxlen=79
fullName Text maxlen=500
email Text maxlen=190
avatar Text maxlen=190
note Text sqltype=mediumtext
UniqueUser username
UniqueEmail email

View File

@ -51,7 +51,6 @@ dependencies:
- conduit-combinators >= 1.1 && <1.2
- friendly-time >=0.4 && <0.5
- foreign-store >=0.2 && <0.3
- libravatar >=0.4 && <0.5
- slug >=0.1 && <0.2
- split >=0.2 && <0.3
- yesod-auth-hashdb >=1.6.2 && <1.7

View File

@ -7,11 +7,6 @@ import Import
import Data.Maybe (fromJust)
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Network.Libravatar as L
libravatar :: (MonadIO m) => User -> m (Maybe Text)
libravatar = liftIO . flip L.avatarUrl opts . L.Email . userEmail
where opts = def { L.optSecure = True, L.optSize = L.Size 512, L.optTryGravatar = False }
entityToTuple :: Entity t -> (Key t, t)
entityToTuple (Entity key value) = (key, value)
@ -30,7 +25,6 @@ routeFromPgp PgpKey { pgpKeyFingerprint = f } = staticR ["pgp", T.takeEnd 8 f ++
hCard :: Entity User -> Widget
hCard (Entity userId user) = do
maybeAvatar <- libravatar user
mcurrentRoute <- getCurrentRoute
userProfiles <- handlerToWidget . runDB $ do
profiles <- map entityVal <$> selectList [ProfileUserId ==. userId] []

View File

@ -39,8 +39,7 @@ packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:
- libravatar-0.4.0.1
extra-deps: []
# Override default flag values for local packages and extra-deps
flags: {}

BIN
static/img/dewdrop wink.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -2,8 +2,7 @@
$maybe route <- mcurrentRoute
<a .u-uid.u-url itemprop="url" href=@{route} hidden>
$maybe avatar <- maybeAvatar
<img .card-img-top.u-photo itemprop="image" src=#{avatar} alt="Avatar for #{userFullName user}">
<img .card-img-top.u-photo itemprop="image" src=@{staticR ["img", userAvatar user]} alt="Avatar for #{userFullName user}">
<div .card-body>
<h4 .card-title.p-name itemprop="name">#{userFullName user}