e28a215c |
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 | */}} |
2882a244 |
28 | |
e28a215c |
29 | {{- if .Get "mail" -}} |
30 | {{- $mailaddr := .Get "mail" -}} |
31 | {{- .Scratch.Set "mailhash" $mailaddr -}} |
32 | {{ else }} |
33 | {{- .Scratch.Set "mailhash" $.Site.Params.author_email -}} |
34 | {{ end }} |
35 | {{- $hash := .Scratch.Get "mailhash" | lower | md5 -}} |
36 | |
37 | <figure{{ with .Get "class" }} class="{{ . }}"{{ end }}> |
38 | {{- if .Get "link" -}} |
39 | <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> |
40 | {{- end }} |
41 | <img src="https://www.gravatar.com/avatar/{{- $hash -}}?s={{- with .Get "size" }}{{.}}{{ else }}200{{ end }}" |
42 | {{- if or (.Get "alt") (.Get "caption") }} |
43 | alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}" |
44 | {{- end -}} |
45 | /> |
46 | {{- if .Get "link" -}} |
47 | </a> |
48 | {{- end }} |
49 | {{- if .Get "caption" -}} |
50 | <figcaption> |
51 | <p> |
52 | {{- .Get "caption" | markdownify -}} |
53 | </p> |
54 | </figcaption> |
55 | {{- end }} |
56 | </figure> |