Skip to content

Instantly share code, notes, and snippets.

@LordAmit
Created June 27, 2018 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LordAmit/7dbc05f30a275f8f297a8452d0cc1858 to your computer and use it in GitHub Desktop.
Save LordAmit/7dbc05f30a275f8f297a8452d0cc1858 to your computer and use it in GitHub Desktop.
hugo amp lightbox image shortcode with unique ID assignment
<!-- you also need to add the following script
<script async custom-element="amp-image-lightbox" src="https://cdn.ampproject.org/v0/amp-image-lightbox-0.1.js"></script>
-->
{{$unique_id := now.UnixNano}}
<amp-image-lightbox id="{{ $unique_id }}"
layout="nodisplay"></amp-image-lightbox>
<figure {{ if .Get "class" }} class='{{ .Get "class" }}'
{{else}} class="image-center" {{ end }} >
<amp-img
on='tap:{{ $unique_id }}'
tabindex="0"
role="button"
src="{{ .Get "src" }}"
alt="{{ .Page.Title }} {{ .Get "src" }}"
width={{ .Get "w" | default "200" }}
height={{ .Get "h" | default "200"}}>
</amp-img>
{{ if .Get "caption" }}
<figcaption>
{{ if .Get "href" }}
<a href="{{ .Get "href" }}" target="_blank">{{ .Get "caption" }}</a>
{{ else }}
{{ .Get "caption" }}
{{ end }}
</figcaption>
{{ end }}
</figure>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment