Created
June 27, 2018 07:25
-
-
Save LordAmit/7dbc05f30a275f8f297a8452d0cc1858 to your computer and use it in GitHub Desktop.
hugo amp lightbox image shortcode with unique ID assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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