Hugo Gravatar Module

Donate

Become a backer or sponsor to support our work.

Sponsors

This module ships with several partials for Gravatar.

Modulegithub.com/hugomods/gravatar
StatsGitHub Stars Used By Used By Used By Used By

Installation

Requires extended Hugo and Go.

Import the github.com/hugomods/gravatar module.

hugo.yaml

1import:
2  modules:
3  - path: github.com/hugomods/gravatar

hugo.toml

1[import]
2  [[import.modules]]
3    path = 'github.com/hugomods/gravatar'

hugo.json

1{
2   "import": {
3      "modules": [
4         {
5            "path": "github.com/hugomods/gravatar"
6         }
7      ]
8   }
9}

Site Parameters

The following parameters can be overridden by partials’ parameters.

NameTypeDefaultDescription
defaultStringmpThe default image. Available options: 404, mp, identicon, monsterid, wavatar, retro, robohash, blank or an image URL.
forceDefaultBooleanfalseForce the default image to always load.
sizeInteger80Single pixel dimension, since the images are square.
ratingString-Available options: g, pg, r and x.
classNameStringgravatar-imgThe class name of img tag.

hugo.yaml

1params:
2  gravatar:
3    default: mp

hugo.toml

1[params]
2  [params.gravatar]
3    default = 'mp'

hugo.json

1{
2   "params": {
3      "gravatar": {
4         "default": "mp"
5      }
6   }
7}

See configuration and Gravatar image request for details.

Partials

PartialDescriptionExample
gravatar/avatarrenders a Gravatar image by a raw email address.{{ partial "gravatar/avatar" "[email protected]" }}
gravatar/avatar-hashrenders a Gravatar image by a MD5 encrypted email address hash.{{ partial "gravatar/avatar-hash" "e7501ec2b3cd95d6af8964743c1d27c7" }}
gravatar/avatar-paramsallow specifying the default image, image size, rating and class name.{{ partial "gravatar/avatar-params" $params }}, see partials’ parameters.
gravatar/avatar-urlreturns the Gravatar image URL instead of img tag.{{ partial "gravatar/avatar-url" $params }}, see partials’ parameters.

You can find more examples on https://hugomods.github.io/gravatar/.

Partials’ Parameters

The following parameters will override the global parameters if present.

NameTypeDescription
IdStringThe MD5 encrypted email address hash, you MUST provide one of the Id or Email.
EmailStringThe raw email address.
AltStringThe alternative text.
DefaultStringThe default image.
ForceDefaultBooleanForce the default image to always load.
SizeIntegerThe image size.
RatingStringThe image rating.
ClassNameStringThe class name of img tag. Doesn’t work with the gravatar/avatar-url partial.
 1{{ $params := dict (
 2    "Id" "e7501ec2b3cd95d6af8964743c1d27c7"
 3    "Size" 120
 4    "Alt" "Foo"
 5    "Default" "monsterid"
 6    "ForceDefault" true
 7    "Rating" "x"
 8    "ClassName" "avatar-img-circle"
 9) }}
10{{ partial "gravatar/avatar-params" $params }}
11{{ partial "gravatar/avatar-url" $params }}