diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-05 09:19:48 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-05 09:19:48 +0200 |
| commit | 627b110437ccd089bc3d9a5160ec41569f114e82 (patch) | |
| tree | c0696e9a37eaad1512c3588ae52cc0f5d19cd842 /layouts | |
| parent | 7c4a9a75c87bdb75e0c16657487e352385e8bdf7 (diff) | |
| download | danixxyz-theme-627b110437ccd089bc3d9a5160ec41569f114e82.tar.gz danixxyz-theme-627b110437ccd089bc3d9a5160ec41569f114e82.zip | |
feat: add gravatar shortcode template
Ported gravatar shortcode from previous theme. Allows embedding Gravatar images with customizable size, link, and caption.
Usage: {{< gravatar mail="email@example.com" size=150 link="https://example.com" caption="Profile photo" >}}
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/shortcodes/gravatar.html | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/layouts/shortcodes/gravatar.html b/layouts/shortcodes/gravatar.html new file mode 100644 index 0000000..56e2514 --- /dev/null +++ b/layouts/shortcodes/gravatar.html @@ -0,0 +1,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> |
