# Gallery Shortcode I'm using the following shortcode (saved as `gallery.html`) in Hugo to generate a gallery containing both video and photos. Comments in the code. May it be helpful for you. It comes (of course) with no support. The cover photo handling is done by my Hugo theme (terminal) btw. ~~~ go-tmpl {{- $videos := .Page.Resources.Match "img/*.webm" -}} {{- $videos = $videos | append ( .Page.Resources.Match "img/*.ogv" ) -}} {{- range $videos -}} {{- $caption := "" -}} {{- $captionfile := printf "%s.%s" ( strings.TrimSuffix (path.Ext .RelPermalink) .RelPermalink ) "txt" -}} {{- if os.FileExists $captionfile -}} {{ $caption = os.ReadFile $captionfile | markdownify -}} {{- end -}} {{- $type := printf "%s/%s" "video" (slicestr (path.Ext .RelPermalink) 1) -}} {{- $type = replace $type "ogv" "ogg" -}}
{{- if $caption -}}

{{ $caption }}

{{- end -}}
{{ end }} {{ $image := (.Page.Resources.ByType "image") }} {{ $i := 0 }} {{ with $image }} {{ range . }} {{ if not ( hasPrefix .Name "cover." ) }} {{ if not ( hasPrefix .Name "img/cover." ) }} {{ if eq (mod $i 3) 0 }}
{{ end }} {{ $resized := .Fill "300x230 q70" }} {{ $caption := "" }} {{ $captionfile := printf "%s.%s" ( strings.TrimSuffix (path.Ext .RelPermalink) .RelPermalink ) "txt" }} {{ if os.FileExists $captionfile }} {{ $caption = os.ReadFile $captionfile | markdownify }} {{ end }}
{{ if $caption }}

{{ $caption }}

{{- end }}
{{ if eq (mod $i 3) 2 }}
{{ end }} {{ $i = add $i 1 }} {{ end }} {{ end }} {{ end }} {{ end }} ~~~