Gallery in Hugo
The visualci-gallery Hugo module puts a public gallery in a Hugo page: a tab for each group, light and dark, desktop and phone, and a full-size view. Its shortcode, in any page's content, and its partial, in a layout, render the gallery into the page's HTML when the site builds. The gallery's script and stylesheet are published with your site, and they bring it to life in the browser. If a manifest can't be read, the build fails.
It needs Hugo 0.146 or later, and Go for Hugo Modules. Add the module to your site (hugo mod init first if your site isn't a Hugo module yet):
hugo mod get github.com/DocSpring/visualci/clients/gallery/hugo@v0.7.0
A gallery needs your project's manifest URL, https://app.visualci.com/g/<org>/<project>.json, which works once the project's gallery is on. The examples use acme/web. Every snippet below is a file from the example site, which VisualCI's tests build with hugo and check in a browser.
The module
Import it in hugo.toml:
baseURL = "https://acme.example/"
title = "Acme"
disableKinds = ["taxonomy", "term", "RSS", "sitemap"]
[module]
[[module.imports]]
path = "github.com/DocSpring/visualci/clients/gallery/hugo"
The first gallery on a page adds the gallery's stylesheet and script before it. When the site builds, the module downloads them from jsDelivr, at the version the module was released with, and publishes them with your site, fingerprinted. To keep the build from downloading them, put your own copies of the JS library's gallery.css and gallery.iife.js in assets/visualci-gallery/. If you add them to your pages yourself, set params.visualciGallery.assets = false.
The smallest page
content/screenshots.md:
---
title: Screenshots
---
{{< visualci-gallery manifest="https://app.visualci.com/g/acme/web.json" />}}
Use {{< >}}, not {{% %}}, so Markdown leaves the gallery's HTML alone. Each manifest is read once a build, however many pages show it. The image URLs always serve the approved version, so a changed screenshot shows on your site without a rebuild. A new screenshot, or one whose size changed, shows after the next build.
Options
Options go inside the shortcode as YAML, in the gallery's own spelling (headingLevel, groupOrder, themeSwitch, seeAll, deepLinks, newBadges). On this page the gallery gets a heading, and two screens get a title and a caption. order puts two screens first. The Mac approver group gets a new title and shows its windows whole, and the iPhone tab comes first:
---
title: Tour
---
{{< visualci-gallery >}}
manifest: https://app.visualci.com/g/acme/web.json
title: See it in action
headingLevel: 2
screens:
overview: {title: Overview, caption: "What needs you, at a glance."}
ios/sessions: {title: Sessions, caption: Every session on every machine.}
order: [overview, access]
groups:
Mac approver: {title: On the Mac, fit: contain}
groupOrder: [iPhone, Web]
{{< /visualci-gallery >}}
An option with a plain value can be a parameter instead: {{< visualci-gallery manifest="…" layout="strip" credit=true />}}. Giving an option both ways fails the build. A screen's key is its screenshots' name without the theme and width: overview-light-1440 and overview-dark-390 are the screen overview. Groups go by the names in visualci.yml's gallery section. title: null leaves the gallery's heading out, under the page's own. Quote a screen key or group name that YAML would read as something else: "on", "no", "2024". Give each gallery on a page its own id. deepLinks: true puts the open tab and screen in the page's URL (Deep links), and text changes the gallery's words, for another language (Your own words). Gallery options describes every option, and how screenshot names pair into screens.
In a layout
The visualci-gallery.html partial takes the page, manifest and the options in one dict. The example site's layouts/home.html puts a band of every screen on the homepage. The strip layout shows every screen at one size in a single row that scrolls sideways, with no tabs and no captions, and seeAll links to the full page:
{{ define "main" }}
<h1>{{ site.Title }}</h1>
{{/* A band of every screen, linking to the full page: the partial, for a layout. */}}
{{ partial "visualci-gallery.html" (dict
"page" .
"manifest" "https://app.visualci.com/g/acme/web.json"
"layout" "strip"
"title" nil
"seeAll" (dict "href" ("screenshots/" | relURL))
) }}
{{ end }}
manifest can also be a manifest you've already read, from your site's data files for one.
One screenshot
The visualci-screenshot shortcode shows one screen from the same manifest, in the reader's light or dark mode, with no script or stylesheet. See One screenshot for its options and the partial.
Theming
Set the --vg-* variables to your site's tokens, and the gallery's colours follow its light and dark mode. Declare color-scheme for each mode too: the gallery's other colours follow it. From the example site's static/site.css:
.vg {
--vg-ink: var(--color-text);
--vg-muted: var(--color-muted);
--vg-paper: var(--color-bg);
--vg-accent: var(--color-brand);
}
Gallery options lists every variable.
Light and dark
By default each group has Light and Dark buttons. The gallery starts in the page's theme, and the buttons switch the screenshots without changing your page. With themeSwitch: false the gallery follows your site's <html data-theme="light"> or "dark" instead, as it changes. The example site's toggle sets it. If your theme marks dark mode another way, such as a dark class, set data-theme too.
---
title: The app
---
The gallery follows the site's light and dark toggle.
{{< visualci-gallery >}}
manifest: https://app.visualci.com/g/acme/web.json
title: null
themeSwitch: false
{{< /visualci-gallery >}}
One release's screenshots
ref: v1.0.0 beside manifest shows the gallery as it was at that release, when your project
reports versions, for a page that documents that release: the module reads
…/web@v1-0-0.json in place of the main manifest. versions: true adds a Version switch over the grid, so readers
can move between Latest and every release (Versions).
When the manifest can't be read
When VisualCI answers with a temporary error (a 5xx, 408 or 429), Hugo tries again until the site's timeout. Then the build fails with an error that names the page and the URL. It also fails when the manifest has nothing to show, an option is invalid or misspelled, or the YAML inside the shortcode doesn't parse. The site you have keeps serving its last build until VisualCI answers again.
Hugo keeps what it downloads in its cache, so the module reads each manifest under a new key every build, and an old copy is never shown. Build with hugo --gc now and then to clear the old copies. hugo server reads the manifest when it starts.
Pinning the version
hugo mod get writes the version to your site's go.mod, so an update is a change you make:
hugo mod get github.com/DocSpring/visualci/clients/gallery/hugo@v0.7.0