The gallery.json file controls your gallery's structure, metadata, and organization. This file is created by the init command but can be manually edited for advanced customization.
This page explains how to use the advanced configuration options.
See also: Commands Reference | Deployment Guide | Main Documentation
Site metadata
The site metadata is used by search engines and social media platforms to get structured data for your site and display a nice-looking card. Simple Photo Gallery has already automated part of this by setting the title and description of the gallery and generating a social media card from the header image.
However, you may want to add some more information using the following parameters:
author- The author of the sitekeywords- The keywords of the sitelanguage- The language of the siterobots- The robots of the siteogType- The type of the site, e.g.websiteorarticleogSiteName- The name of the sitetwitterSite- The site to use for the social media cardtwitterCreator- The creator to use for the social media card
Additionally, the following parameters are automatically generated, but you can override them:
canonicalUrl- The canonical URL of the siteogUrl- The URL of the siteogImage- The image to use for the social media cardogImageWidth- The width of the imageogImageHeight- The height of the image
Structured data
The gallery page includes schema.org ImageGallery structured data as a JSON-LD script in the page head. Search engines can use it to understand that the page is a photo gallery and which photos and videos it contains. It contains:
nameanddescription- The gallery title and the description as plain text (Markdown is removed)url-metadata.canonicalUrl, the galleryurl, ormetadata.ogUrl, in that orderinLanguage,author, andkeywords- Fromlanguage,author, andkeywordsinmetadata, when setimage- The social media card imagemainEntity- AnItemListwith anImageObjectorVideoObjectfor each photo and video, with its URL, thumbnail URL, dimensions, and caption as plain text
Search engines need absolute URLs, so set the gallery url (or metadata.canonicalUrl) to the address where the gallery is hosted. Relative photo, thumbnail, and image paths are resolved against it. Without a gallery URL, only paths that are already absolute (for example with mediaBaseUrl set to a full URL) are included, and photos without an absolute URL are left out.
To keep the page small, the list contains at most the first 100 photos and videos. numberOfItems still reports the total count.
Structured data is enabled by default. To turn it off, set structuredData to false in metadata:
{
"metadata": {
"structuredData": false
}
}
Theme
You can specify the theme to use for your gallery by setting the theme field in gallery.json. This allows each gallery to use a different theme without needing to specify it via CLI each time.
{
"title": "My Gallery",
"theme": "@simple-photo-gallery/theme-modern"
}
The theme can be specified as:
- An npm package name (e.g.,
@simple-photo-gallery/theme-modern) - A local path (e.g.,
./themes/my-custom-theme)
Theme Resolution Priority
When building a gallery, the theme is resolved in this order:
- CLI option (highest priority) -
--themeflag - gallery.json - The
themefield in your gallery configuration - Default theme (lowest priority) -
@simple-photo-gallery/theme-modern
When you specify a theme via the CLI --theme flag, it is saved to gallery.json for future builds.
Sections
Sections can be used to group your photos with their own titles and descriptions. This is useful if you have a large gallery and want to split it into smaller sections.
The sections array can be used to define the sections of the gallery. Each section object can have the following properties:
title- The title of the section (optional)description- The description of the section (optional)images- An array of images to display in the section
Photos and videos are shown in the order of the images array, and sections in the order of the sections array. Each section lists its files explicitly. There is no syntax for ranges such as "from IMG_150.jpg to IMG_250.jpg".
Example
A trip gallery with three sections. Only the first image of each section is shown; the width, height and thumbnail values are filled in by the CLI.
{
"title": "Japan 2025",
"description": "Two weeks from Tokyo to Kyoto.",
"sections": [
{
"images": [{ "type": "image", "filename": "00-intro.jpg", "width": 4000, "height": 3000 }]
},
{
"title": "Tokyo",
"description": "Neon nights and quiet *shrines*.",
"images": [{ "type": "image", "filename": "tokyo-001.jpg", "width": 4000, "height": 3000 }]
},
{
"title": "Kyoto",
"images": [{ "type": "image", "filename": "kyoto-001.jpg", "width": 3000, "height": 4000 }]
}
]
}
A section without a title is shown without a heading, which is useful for an introduction. Section descriptions support Markdown.
Splitting existing photos into sections
If all photos are already in the folder, run init once and then split the single generated section in gallery.json:
-
Name or sort the files so that each section's photos are next to each other, for example with a prefix such as
tokyo-andkyoto-.initlists the files sorted by name, with numbers in natural order (IMG_2beforeIMG_10). -
Run
spg initand opengallery/gallery.json. -
Where a new section should start, close the current
imagesarray and section object and open a new one:{ "type": "image", "filename": "tokyo-042.jpg", "width": 4000, "height": 3000 } ] }, { "title": "Kyoto", "images": [ { "type": "image", "filename": "kyoto-001.jpg", "width": 4000, "height": 3000 } -
Add a
titleand optionaldescriptionto each section and runspg build.
You can move entries between sections, or reorder them, at any time. The next build keeps your order.
Adding photos to a section
Do not run init again to add photos to an existing gallery: it creates a new gallery.json with a single section, and it only does so after you confirm or pass --force. Copy the new files into the photos folder and run spg build instead. The build scans the folder and adds files that are not in gallery.json yet. It does not change existing sections, their titles and descriptions, or their order.
New files are added to the end of the last section. To add them to a different section, use the --section option with the section title or its number (starting at 1):
spg build --section "Tokyo"
spg build --section 2
You can build a gallery section by section this way:
-
Copy the first batch of photos into the folder, run
spg init, and give the generated section atitleingallery.json. -
Add the next section to the end of the
sectionsarray, with no files yet:{ "title": "Kyoto", "images": [] } -
Copy that section's photos into the folder and run
spg build. Because the new section is the last one, the files are added to it. Usespg build --section "Kyoto"instead if the section is not the last one. -
Repeat for every section.
The section must already exist in gallery.json. If the title does not match any section, or matches several, the build stops with an error listing the sections and leaves gallery.json unchanged.
To remove photos, delete the files and run spg build --prune, which removes their entries from all sections.
Sections or sub-galleries
Sections split one gallery page. To give each group its own page, put each group in a subfolder and run spg init --recursive. The CLI then creates a gallery for every folder and links them as sub-galleries.
Media files
Each item in the images array of a section represents a media file (image or video). Media files have the following properties:
Required properties
type- The type of media:"image"or"video"filename- The filename of the media file (e.g.,"photo-001.jpg")width- The width of the media in pixelsheight- The height of the media in pixels
Optional properties
url- A custom URL for the media file. If provided, this URL will be used directly as the source, regardless of themediaBaseUrlsetting or base path configuration. This is useful when you want to host specific images on different CDNs or use external URLs.alt- A caption/description for the media (supports Markdown formatting)thumbnail- Thumbnail metadata object withpath,pathRetina,width,height, optionalblurHash, and optionalbaseUrlvideoSources- Ordered lightbox video sources. Each entry has asrcURL, a MIMEtype, and an optionalmediaquery. Relative URLs resolve from the gallery page. Place a source without a media query last for other viewport sizes. An omitted or empty list plays the original.srcset- Responsive full-size image candidates used by themes for the lightbox, formatted like a standard imagesrcsetvaluelastMediaTimestamp- Timestamp metadata (automatically generated)
URL resolution
By default, the full image URL is constructed by combining the mediaBaseUrl (if set) with the filename. However, if a url field is present, it will always be used instead, ignoring any base URL or path settings.
Example without custom URL:
{
"type": "image",
"filename": "photo-001.jpg",
"width": 1920,
"height": 1080
}
If mediaBaseUrl is set to "https://cdn.example.com/images", the final URL will be "https://cdn.example.com/images/photo-001.jpg".
Example with custom URL:
{
"type": "image",
"filename": "photo-001.jpg",
"url": "https://special-cdn.example.com/custom-path/photo-001.jpg",
"width": 1920,
"height": 1080
}
The final URL will always be "https://special-cdn.example.com/custom-path/photo-001.jpg", regardless of the mediaBaseUrl setting.
Example with responsive full-size candidates:
{
"type": "image",
"filename": "photo-001.jpg",
"url": "https://cdn.example.com/images/photo-001.jpg",
"width": 4000,
"height": 3000,
"srcset": "https://cdn.example.com/images/photo-001-1280.jpg 1280w, https://cdn.example.com/images/photo-001-1920.jpg 1920w"
}
Example lightbox video with two pre-encoded sources:
{
"type": "video",
"filename": "clip.mov",
"width": 1920,
"height": 1080,
"videoSources": [
{ "src": "variants/clip-720.mp4", "type": "video/mp4", "media": "(max-width: 900px)" },
{ "src": "variants/clip-1080.mp4", "type": "video/mp4" }
]
}
Thumbnail URL resolution
By default, thumbnail URLs are constructed by combining the thumbsBaseUrl (if set at the gallery level) with the thumbnail path or pathRetina. However, you can override this for individual thumbnails by setting a baseUrl property directly on the thumbnail object.
Priority order for thumbnail URLs:
- If a thumbnail has a
baseUrlproperty, it will be used to construct the URL:${thumbnail.baseUrl}/${path}or${thumbnail.baseUrl}/${pathRetina} - Otherwise, if
thumbsBaseUrlis set at the gallery level, it will be used:${thumbsBaseUrl}/${path}or${thumbsBaseUrl}/${pathRetina} - Otherwise, thumbnails will use the default relative path:
gallery/images/${path}
Example with gallery-level thumbsBaseUrl:
{
"thumbsBaseUrl": "https://cdn.example.com/thumbs",
"sections": [
{
"images": [
{
"type": "image",
"filename": "photo-001.jpg",
"width": 1920,
"height": 1080,
"thumbnail": {
"path": "photo-001.avif",
"pathRetina": "[email protected]",
"width": 300,
"height": 200
}
}
]
}
]
}
The thumbnail URLs will be:
- Regular:
https://cdn.example.com/thumbs/photo-001.avif - Retina:
https://cdn.example.com/thumbs/[email protected]
Example with thumbnail-specific baseUrl:
{
"thumbsBaseUrl": "https://cdn.example.com/thumbs",
"sections": [
{
"images": [
{
"type": "image",
"filename": "photo-001.jpg",
"width": 1920,
"height": 1080,
"thumbnail": {
"baseUrl": "https://special-cdn.example.com/custom-thumbs",
"path": "photo-001.avif",
"pathRetina": "[email protected]",
"width": 300,
"height": 200
}
}
]
}
]
}
The thumbnail URLs will be:
- Regular:
https://special-cdn.example.com/custom-thumbs/photo-001.avif - Retina:
https://special-cdn.example.com/custom-thumbs/[email protected]
The thumbnail-specific baseUrl overrides the gallery-level thumbsBaseUrl, allowing you to host specific thumbnails on different CDNs or use external URLs.
Note: When building galleries with the CLI, thumbnail-specific
baseUrlvalues are preserved and will not be overwritten by the--thumbs-base-urloption.
Sub-galleries
Sub-galleries are links to other galleries, typically located in subdirectories of the photos folder. They are used to create navigation between galleries and sub-galleries.
Sub-galleries are generated automatically when you initialize the gallery in the top-level folder with the -r or --recursive flag. After that, you can edit the subGalleries attribute in the gallery.json file if you want to use different titles or images for the links.
Captions
When displaying photos and videos in full screen, you can show captions at the bottom. The captions are automatically extracted from the EXIF data of the photos if you used a tool to add them. If not, you can add them manually in the gallery.json file using the alt attribute of each image or video.
Markdown captions
If you prefer to keep captions out of your photos' EXIF data and out of a long gallery.json, you can write each caption in a Markdown file next to its photo or video. This is off by default. Turn it on by setting markdownCaptions in gallery.json, or by passing --markdown-captions to spg init:
{
"title": "My Gallery",
"markdownCaptions": true
}
For each photo or video, the CLI looks for a Markdown caption file in the folder that holds the original files (the gallery folder, or mediaBasePath when it is set):
<filename>.md, for exampleIMG_0042.jpg.md<name without extension>.md, for exampleIMG_0042.md
The first one found is used. A <name>.md file also applies to other media with the same name, for example IMG_0042.jpg and IMG_0042.mov. The CLI warns when that happens; use the full filename to caption only one of them.
The Markdown body of the file becomes the caption (alt) and supports the same Markdown formatting as other captions:
Sunset over **Lake Kawaguchi**, the evening before the climb.
A file can start with a --- frontmatter block. Frontmatter is not shown in the caption. A single-line caption: (or alt:) key in the frontmatter is used instead of the body. Other keys are ignored with a warning.
---
caption: Sunset over **Lake Kawaguchi**
---
Markdown captions are applied every time thumbnails are generated (spg thumbnails or spg build, also with --no-thumbnails), including for photos whose thumbnails are already up to date. When markdownCaptions is on, the caption sources take this priority:
- The Markdown caption file
- The
altvalue already ingallery.json, including captions you edited by hand - The EXIF caption of the photo, which is read when a photo is first processed or when the photo file changes
Media without a caption file keep their current behaviour. Empty caption files are ignored. If you delete a caption file, the last caption stays in gallery.json; edit or remove it there. Caption files larger than 64 KB, and caption files that resolve to a location outside the media folder (for example through a symbolic link), are ignored.
Markdown formatting
Gallery descriptions, section descriptions, and image captions support Markdown formatting for rich text styling. This allows you to add emphasis, links, lists, and code snippets to your text.
Supported Markdown features
The following Markdown elements are supported:
- Bold text - Use
**bold**or__bold__ - Italic text - Use
*italic*or_italic_ - Links - Use
[link text](url) - Lists - Both ordered (
1. Item) and unordered (- Item) Inline code- Use backticks:`code`- Code blocks - Use triple backticks:
``` code block ``` - Block quotes - Use
> quote text
Where you can use Markdown
Markdown formatting is available in:
- Gallery description - The main description shown on the hero section
- Section descriptions - Descriptions for each gallery section
- Image/video captions - The
altattribute of images and videos
Example
{
"title": "My Gallery",
"description": "Welcome to my **photo collection**! Check out [my website](https://example.com) for more.",
"sections": [
{
"title": "Tokyo 2024",
"description": "Photos from *Japan* featuring:\n\n- Cherry blossoms\n- Street photography\n- `Fujifilm X-T5`",
"images": [
{
"type": "image",
"filename": "tokyo-001.jpg",
"width": 1920,
"height": 1080,
"alt": "Sunset at **Mount Fuji** - taken with `50mm f/1.8`"
}
]
}
]
}
Styling notes
- Links are styled with a subtle gray color that stands out from regular text
- Headings in Markdown are automatically converted to paragraphs to maintain consistent styling
- Images and tables are not supported for security and layout consistency
- HTML tags are stripped for security
Custom CSS
You can restyle any part of the gallery with your own stylesheet. Set stylesheetUrl in gallery.json to the URL of a CSS file:
{
"title": "My Gallery",
"stylesheetUrl": "custom.css"
}
The stylesheet is loaded after the theme styles, so your rules override theme rules of the same specificity. Use your browser's developer tools to find the elements you want to change.
Theme rules are scoped to their components: a rule written for .hero__title is published as .hero__title[data-astro-cid-…], which counts as two class-level selectors. A selector with a single class, such as .hero__title, therefore does not override it. Combine at least two classes, or a class and an attribute, for example:
/* custom.css */
.hero .hero__title {
font-family: Georgia, serif;
letter-spacing: 0.05em;
}
.gallery-section .gallery-section__header-title {
color: #7c2d12;
}
stylesheetUrl can be:
- A path relative to the gallery page (
index.html), for examplecustom.cssorstyles/custom.css. Keep the file next toindex.html(in the photos folder, or in the gallery folder if you usedinit --gallery) and deploy it with the gallery. Do not put it inside the generatedgallery/subfolder, becausespg cleanremoves everything there exceptgallery.json. - A full URL, for example
https://cdn.example.com/galleries/custom.css, to share one stylesheet between several galleries.
Paths that start with / are rewritten to be relative to the gallery page, like all other links in the generated HTML. Use a full URL if the stylesheet lives at the root of a different site.
The rules apply to the theme's HTML, so class names can change between theme versions. Check your stylesheet after you upgrade the theme. To build a new layout or new components, create a custom theme instead.
Thumbnail Configuration
Thumbnail generation and display can be configured through a hierarchical configuration system:
Migration Note: If you're upgrading from an older version that used
thumbnailSize(a number field), this has been replaced with athumbnailsobject containingsizeandedgeproperties. Your existingthumbnailSizevalue will be automatically migrated tothumbnails.sizewhen you run any gallery command.
- CLI options (highest priority) - Passed via
--thumbnail-sizeand--thumbnail-edgeflags - Gallery-level configuration - Set in
gallery.json - Theme-level configuration - Set in theme's
themeConfig.jsonfile - Built-in defaults (lowest priority) - 300px on auto (longer edge)
Configuration Hierarchy
The thumbnail settings follow this priority order:
CLI options > gallery.json > themeConfig.json > built-in defaults
This means CLI options always take highest priority, followed by gallery.json settings. If not specified in either, the theme's themeConfig.json will be checked. If neither is set, the built-in defaults (300px, auto edge) will be used.
When you provide thumbnail settings via CLI flags to the init, thumbnails, or build commands, those settings are saved to gallery.json for future builds.
Gallery-level Configuration
You can override thumbnail settings per gallery by adding a thumbnails object to your gallery.json:
{
"title": "My Gallery",
"thumbnails": {
"size": 400,
"edge": "height"
}
}
Options:
size(number): The thumbnail size in pixels. Default:300edge(string): How the size is applied. Default:"auto""auto"- Applied to the longer edge (default behavior)"width"- Applied to width (good for masonry layouts)"height"- Applied to height (good for row-based layouts like modern theme)
Theme-level Configuration
Themes can provide their own default thumbnail settings by including a themeConfig.json file in the theme root directory:
{
"thumbnails": {
"size": 300,
"edge": "height"
}
}
This allows theme authors to set optimal defaults for their specific layout while still allowing users to override these settings per gallery.
For theme developers: Place themeConfig.json in your theme's root directory (same level as package.json). The configuration will be automatically loaded when the theme is used.
Display Behavior
When thumbnails are configured, they also control the display size in themes:
- Modern theme:
thumbnails.sizebecomes the row height (e.g.,size: 200sets--row-height: 200px) - Default behavior (no thumbnails config): Uses responsive breakpoints (96px on mobile, scaling up to 160px on desktop)
CLI Configuration
You can configure thumbnail settings when running gallery init, gallery thumbnails, or gallery build by using the CLI flags:
# Set thumbnail size and edge during init
gallery init --thumbnail-size 400 --thumbnail-edge height
# Override settings when generating thumbnails
gallery thumbnails --thumbnail-size 300 --thumbnail-edge auto
# Override settings when building
gallery build --thumbnail-size 400 --thumbnail-edge height
When provided via CLI, these settings are saved to gallery.json for future builds, keeping the configuration hierarchy consistent.
Header image variants
By default, the hero section generates responsive image paths based on the headerImage filename using a naming convention (e.g., photo_portrait_360.avif, photo_landscape_1920.jpg). If you need to specify custom paths for the hero image variants, you can use the headerImageVariants configuration.
When headerImageVariants is set, only the formats and sizes you explicitly specify will be rendered. Any format or orientation not included will be omitted from the HTML output entirely.
Structure
All fields are optional. You only need to include the formats and sizes you want to use:
{
"headerImageVariants": {
"portrait": {
"avif": {
"360": "path/to/portrait_360.avif",
"480": "path/to/portrait_480.avif",
"720": "path/to/portrait_720.avif",
"1080": "path/to/portrait_1080.avif"
},
"jpg": {
"360": "path/to/portrait_360.jpg",
"480": "path/to/portrait_480.jpg",
"720": "path/to/portrait_720.jpg",
"1080": "path/to/portrait_1080.jpg"
}
},
"landscape": {
"avif": {
"640": "path/to/landscape_640.avif",
"960": "path/to/landscape_960.avif",
"1280": "path/to/landscape_1280.avif",
"1920": "path/to/landscape_1920.avif",
"2560": "path/to/landscape_2560.avif",
"3840": "path/to/landscape_3840.avif"
},
"jpg": {
"640": "path/to/landscape_640.jpg",
"960": "path/to/landscape_960.jpg",
"1280": "path/to/landscape_1280.jpg",
"1920": "path/to/landscape_1920.jpg",
"2560": "path/to/landscape_2560.jpg",
"3840": "path/to/landscape_3840.jpg"
}
}
}
}
Examples
AVIF only (no JPG fallback):
{
"headerImageVariants": {
"landscape": {
"avif": {
"1920": "hero/landscape_1920.avif",
"3840": "hero/landscape_3840.avif"
}
}
}
}
This will only render the landscape AVIF source element with the specified sizes. No portrait sources or JPG fallbacks will be included.
Landscape only (for wide hero images):
{
"headerImageVariants": {
"landscape": {
"avif": {
"1280": "https://cdn.example.com/hero_1280.avif",
"1920": "https://cdn.example.com/hero_1920.avif"
},
"jpg": {
"1280": "https://cdn.example.com/hero_1280.jpg",
"1920": "https://cdn.example.com/hero_1920.jpg"
}
}
}
}
This configuration omits portrait variants entirely, which is useful when your hero image is designed only for landscape orientations.
Note: The
headerImagefield is still used as the fallback<img>source when responsive images fail to load. Make sure it points to a valid image.
Analytics script
You can add custom analytics scripts (such as Google Analytics, Plausible, or other tracking services) to your gallery by including an analyticsScript field in your gallery.json file. The script will be embedded at the end of the HTML body tag.
Example
{
"title": "My Gallery",
"description": "My gallery with fantastic photos.",
"analyticsScript": "<!-- Google Analytics -->\n<script async src=\"https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID\"></script>\n<script>\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', 'GA_MEASUREMENT_ID');\n</script>",
...
}
Security Note: The
analyticsScriptfield accepts arbitrary HTML and JavaScript that will be embedded directly into your gallery. Only add scripts from trusted sources and never include user-provided content in this field. This field is intended to be edited by the gallery owner, not by end users.
Back-to-top link
Galleries built with the modern theme show a small back-to-top link in the bottom-right corner once the visitor has scrolled down. It is on by default. The link moves both the scroll position and keyboard focus back to the top of the page, uses smooth scrolling only when the visitor has not asked for reduced motion, and its label follows the gallery's interface language. Without JavaScript it is a plain link to the top of the page that stays visible.
To remove it, set backToTop to false in gallery.json and rebuild the gallery:
{
"title": "My Gallery",
"backToTop": false
}
When embedding, you can also hide it for a single page view with the ?backToTop=false query parameter.