Page Gallery

approved

by Nathan Clark

Create an embeddable gallery based on selected page contents.

83 stars14,385 downloadsUpdated 7mo agoMIT
View on GitHub

Obsidian Page Gallery

Generates a gallery view of selected pages based on images found in them.

[!CAUTION] Obsidian now has a built-in Bases feature that accomplishes what this plugin was intended to do. While it's still somewhat limited (e.g. only displays images in page properties, not from page content), I doubt it will remain that way for long. As a result, I am unlikely to extend or enhance the Page Gallery plugin beyond its current capabilities, and encourage current users to switch to Bases if they're able to. I will continue to make bug fixes to this plugin in its current state for the time being, but don't expect any major changes or new functionality.

Warning: This plugin is in development and should be considered unstable! Always make a backup of your vault before testing out a new plugin.

Prereqs

Depends on obsidian-dataview to list pages and page metadata.

Usage

Create a code block with type page-gallery:

```page-gallery
# Any options given at the root level of the configuration
# will be used as defaults for all views (but can be overridden
# in any individual view).
fields: [file.name]
columns: 3
orientation: landscape

# If you don't include an explicit `views` option (which needs
# to be an array), then page-gallery will just use all the root
# level options as a single unnamed view.
views:
  - name: Yosemite
    from: '"Images" AND #yosemite'
  - name: Yellowstone
    from: '"Images" AND #yellowstone'
    columns: 4
    orientation: portrait
```

Example of the page-gallery plugin in use

Photos from Unsplash and Pixabay

Settings

Options in the page-gallery block are parsed using YAML.

OptionTypeDefaultDescription
titlestringnullAn optional title for the page gallery.
filterbooleantrueWhether or not to show the filter bar.
countbooleantrueWhether to show view and group counts.
debugbooleanfalseWhether or not to display debug information. Useful primarily for development.
viewsViewConfig[][]A list of individual view configuration blocks (see below).

View Settings

A page gallery consists of a list of views (or tabs), each with its own view settings. Valid view settings are listed below. Any of this view settings can be set in the root of the configuration as well, in which case they act as defaults for all defined views.

If no views are defined, the page gallery will have a single view, based on the values defined in the root configuration.

OptionTypeDefaultDescription
namestring"View #"Optional name or title for the view.
mode"auto","image","content""auto"Whether to show the first image found in the page ("image"), the rendered markdown content of the page ("content"), or automatically fall back to content only if an image isn't found ("auto").
fromstring-Query for pages to include in the gallery. Uses the same query syntax as obsidian-dataview.
wherestring-Additional expression to filter out pages that you want to omit from the gallery.
fieldsstring[][]List of fields to display in the gallery, under the image. Supports both frontmatter and inline fields.
limitnumber100Limit on the number of pages that will be displayed in the gallery. Set this to null to display all of the pages matched by the from query.
groupBystring-Groups pages by a particular field (or obsidian-dataview expression).
sortBystring[]['file.path']One or more fields/expressions to sort the pages by. Prefix with a - sign (e.g. -file.path) to reverse the sort order.
columnsnumber4Number of columns to display at full width.
orientation"portrait","landscape","square""portrait"Whether to display tiles in portrait, landscape, or square mode.

Advanced View Settings

The following settings directly modify the CSS style attributes that are generated for the page gallery in order to allow fine-tuning of image sizes and positioning (overriding the "orientation" and "columns" settings). They should be used with caution, as they will likely conflict or overlap with other applied styles; and may be removed in the future in order to simplify gallery styles and make it easier to keep things working across devices with different screen sizes (requiring you to use custom CSS snippets instead if you want to customize the page gallery styling to this degree).

OptionTypeDefaultDescription
gutterSizestring"0.5em"Size of the gutter between images.
radiusstring"10px"Radius of the corners of each tile.
widthstringCalculated from columns.Display width of each image in the gallery. Overrides columns.
heightstringCalculated from columns and selected orientation.Display height of each image in the gallery.
sizestringcoverHow the image should be scaled to fit within the gallery tile. See CSS background-size for available options.
positionstringcenterPositioning of each image in the gallery. Try top, center, or bottom (etc) to change what parts of the images are visible. See CSS background-position for available options.
repeatstringno-repeatWhether to repeat (i.e. tile) the image in each gallery item. See CSS background-repeat for available options.

Additionally, the size, position, repeat and imageSrc values can be overridden on a specific page via YAML frontmatter:

---
pageGallery:
  size: contain
  position: left
  repeat: repeat-x
  imageSrc: different-image.png
---

Caution: This will override those settings for any page gallery that the page appears in.

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.