Created
April 14, 2019 11:22
-
-
Save robshep/feb28db3f9af67ca55b9cb153f2ca6e3 to your computer and use it in GitHub Desktop.
Testing out Hugo's image finding routine in the twitter_card shortcode
This file contains 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
<!-- save in /layouts/shortcodes/tct.html --> | |
<!-- usage: {{< tct >}} --> | |
<div> | |
{{- with $.Page.Params.images -}} | |
<span>Image: page.params.images[0]: <code>{{ index . 0 | absURL }}</code> </span> | |
{{ else -}} | |
{{- $images := $.Page.Resources.ByType "image" -}} | |
{{- $featured := $images.GetMatch "*feature*" -}} | |
{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}} | |
{{- with $featured -}} | |
<span>Image: page.resources./.*featured.*/: <code>{{ $featured.Permalink }}</code></span> | |
{{- else -}} | |
{{- with $.Site.Params.images -}} | |
<span>Image: site.params.images[0]: <code>{{ index . 0 | absURL }}</code></span> | |
{{ else -}} | |
{{- end -}} | |
{{- end -}} | |
{{- end }} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment