{{/* Bootstrap Carousel A slideshow component for cycling through images like a carousel. https://getbootstrap.com/docs/5.1/components/carousel/ Serve responsive images https://web.dev/serve-responsive-images/ https://cloudfour.com/thinks/responsive-images-the-simple-way/ https://responsivebreakpoints.com/ Lazy loading https://github.com/aFarkas/lazysizes Fixing The Resizing Problem Setting Height And Width On Images Is Important Again https://www.smashingmagazine.com/2020/03/setting-height-width-images-important-again/ New aspect-ratio CSS property supported in Chromium, Safari Technology Preview, and Firefox Nightly https://web.dev/aspect-ratio/ Image descriptions Images are looked for in the page's own bundle first, then in assets. Only page resources can carry metadata, so that is the only way to give a slide a real description: resources: - src: "carousel/skyline.jpg" params: alt: "The city skyline at dusk" An image with no description is treated as decorative - it gets alt="" so screen readers skip it rather than reading out a filename - and the build warns, because a photograph in a carousel usually does carry meaning. Parameters: - "imagesPattern" to pass to resources.Match - "aspectRatio" to be used in aspect-ratio CSS property (default "16/9") - "crossFade" boolean to animate slides with a fade transition instead of a slide (default false) - "withIndicators" boolean to add the indicators to the carousel, alongside the controls (default false) - "withControls" boolean to add the previous and next controls (default false) Example: partial "carousel.html" (dict "context" . "imagesPattern" "carousel/home/*.png" "aspectRatio" "8/3" "withControls" true) */}} {{/* warnf "Carousel imagesPattern: '%+v'" .imagesPattern */}} {{/* warnf "Carousel aspectRatio: '%+v'" .aspectRatio */}} {{/* warnf "Carousel crossFade: '%+v'" .crossFade */}} {{/* warnf "Carousel withIndicators: '%+v'" .withIndicators */}} {{/* warnf "Carousel withControls: '%+v'" .withControls */}} {{/* The page's own bundle first, assets second. Only page resources can carry front matter metadata, so this is what makes a described slide possible at all; the assets fallback keeps every existing site working unchanged. */}} {{ $page := .context.Page }} {{ $images := or ($page.Resources.Match .imagesPattern) (resources.Match .imagesPattern) }} {{/* Resolve each description once - the indicators and the slides need the same answer, and it should not be computed twice. .Title is not a description: Hugo falls back to the resource name when no title is set, so it holds a filename ("skyline.jpg") for a page resource and a path ("/carousel/skyline.jpg") for an asset. Comparing it against .Name is what tells a real title apart from that default. */}} {{ $slides := slice }} {{ range $images }} {{ $alt := "" }} {{ with .Params.alt }}{{ $alt = . }}{{ end }} {{ if and (not $alt) (ne .Title .Name) }}{{ $alt = .Title }}{{ end }} {{ if not $alt }} {{ warnf "Carousel: %q on %s has no description - rendering it as decorative (alt=\"\"). Add params.alt for it under `resources` in the page front matter." .Name $page.RelPermalink }} {{ end }} {{ $slides = $slides | append (dict "image" . "alt" $alt) }} {{ end }}