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