| 1 | {{/* |
| 2 | * The gravatar shortcode: |
| 3 | * All arguments are optional, main ones are mail and size and have a fallback set in place. |
| 4 | * Args: |
| 5 | * mail: [string] The email address. Falls back to .Site.Params.author_email which should be set in your config file. |
| 6 | * size: [int] The size of the fetched image. Defaults to 200 if not set. |
| 7 | * class: [string] The class to give to the figure block. |
| 8 | * link: [string] The address to link the picture to. |
| 9 | * target: [string] Where to open the link. One of "_blank", "_self", "_parent", "_top". |
| 10 | * caption: [string] Caption text to show with the image. Supports Markdown. |
| 11 | * |
| 12 | * Usage: |
| 13 | * {{< gravatar mail="some@address.com" size=150 class="some class" link="https://example.com" target="_blank" rel="author" caption="Here's a picture of a dog." >}} |
| 14 | * |
| 15 | * Output: |
| 16 | * <figure class="some class"> |
| 17 | * <a href="https://example.com" target="_blank" rel="author"> |
| 18 | * <img src="https://www.gravatar.com/avatar/emailhash?s=150" alt="Here's a picture of a dog." /> |
| 19 | * </a> |
| 20 | * <<figcaption> |
| 21 | * <p> |
| 22 | * Here's a picture of a dog. |
| 23 | * </p> |
| 24 | * </figcaption> |
| 25 | * </figure> |
| 26 | * |
| 27 | */}} |
| 28 | {{- if .Get "mail" -}} |
| 29 | {{- $mailaddr := .Get "mail" -}} |
| 30 | {{- .Scratch.Set "mailhash" $mailaddr -}} |
| 31 | {{ else }} |
| 32 | {{- .Scratch.Set "mailhash" $.Site.Params.author_email -}} |
| 33 | {{ end }} |
| 34 | {{- $hash := .Scratch.Get "mailhash" | lower | md5 -}} |
| 35 | |
| 36 | <figure{{ with .Get "class" }} class="{{ . }}"{{ end }}> |
| 37 | {{- if .Get "link" -}} |
| 38 | <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> |
| 39 | {{- end }} |
| 40 | <img src="https://www.gravatar.com/avatar/{{- $hash -}}?s={{- with .Get "size" }}{{.}}{{ else }}200{{ end }}" |
| 41 | {{- if or (.Get "alt") (.Get "caption") }} |
| 42 | alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}" |
| 43 | {{- end -}} |
| 44 | /> |
| 45 | {{- if .Get "link" -}} |
| 46 | </a> |
| 47 | {{- end }} |
| 48 | {{- if .Get "caption" -}} |
| 49 | <figcaption> |
| 50 | <p> |
| 51 | {{- .Get "caption" | markdownify -}} |
| 52 | </p> |
| 53 | </figcaption> |
| 54 | {{- end }} |
| 55 | </figure> |