{{/* Figure Shortcode for Hugo Blox Builder. */}} {{/* Load image from page dir falling back to media library at `assets/media/` and then to remote URI. */}} {{/* Note: Uses `{{-` to unindent HTML so that Figure shortcode can be nested within a `{{%` Markdown shortcode, such as Callout, without the HTML being rendered as a Markdown code block. */}} {{/* Docs: https://hugoblox.com/docs/content/writing-markdown-latex/#single-image Parameters ---------- src : Path to file or url for the image. If a local file, first it is searched in the page directory, and then in `assets/media/` . caption : optional Caption to add to the figure. title : optional DEPRECATED. Legacy alias for 'caption'. lightbox : default "true" If 'lightbox' is "true" and no 'link' is specified, the figure is made zoomable. link : optional Link to open on click instead of zooming on click. id : optional Custom id "figure-{id}" to associate to the
tag. The id defaults to the caption if unset. alt : optional Screen reader text. Defaults to the caption if unset. theme : optional One of ["light", "dark"]. Respectively adds the class ["img-light", "img-dark"] to
. If "light", image is inverted when browsing in dark mode; the opposite otherwise. class : optional Optional additional class for
. max_width : optional `max-width` style attribute for the
tage inside
. For example, "fit-content" makes the
of the same width of the contained image. width : optional `width` attribute of . It defaults to image width. height : optional `height` attribute of . It defaults to image height. numbered : default "false" If "true", the caption is numbered. */}} {{ $destination := .Get "src" }} {{ $is_remote := strings.HasPrefix $destination "http" }} {{ $caption := .Get "caption" | default (.Get "title") | default "" }}{{/* Support legacy `title` option. */}} {{ $zoom := eq (.Get "lightbox" | default "true") "true" }} {{ $id := anchorize (.Get "id" | default ($caption | plainify)) }} {{ $alt := .Get "alt" | default ($caption | plainify) }} {{ $link := .Get "link" }} {{ $zoom = cond (ne $link "") false $zoom }} {{ $img_class := "" }} {{ if eq (.Get "theme" | lower) "light" }}{{ $img_class = printf "%s img-light" $img_class }}{{end}} {{ if eq (.Get "theme" | lower) "dark" }}{{ $img_class = printf "%s img-dark" $img_class }}{{end}} {{/* Workaround Hugo v0.81 error on Windows when `resources.Get (path.Join "media" )` */}} {{- $img := "" -}} {{- if not $is_remote -}} {{- $img = (.Page.Resources.ByType "image").GetMatch $destination -}} {{- if not $img -}} {{- $img = resources.Get (path.Join "media" $destination) -}} {{- end -}} {{- end -}}
{{- if $caption -}} {{/* Localize the figure numbering (if enabled). */}} {{- $figure := split (i18n "figure" | default "Figure %d:") "%d" -}} {{ $caption | markdownify | emojify }} {{- end -}}