Skip to content

gatsby-theme-catalyst-sanity

This theme adds a data layer for SANITY.io on top of gatsby-theme-catalyst-core via component shadowing. This is used as a “core” theme for SANITY.io and is designed to be modified and shadowed itself in the final site. You can see an example of this theme stacked and further customized with gatsby-theme-catalyst-hydrogen.

Demos

Catalyzing Start

gatsby new catalyst-sanity https://github.com/ehowey/gatsby-starter-catalyst-sanity

Sanity Studio

There is a custom sanity studio and data structure located in the starter. This studio should be used as a “base” studio and built on top of for custom content. You can use the desk structure to control whether certain actions are visible to the user or not - e.g. don’t want them to see the “Projects” folder, just hide it via the desk structure.

This is a compromised solution, it makes iterating and building a site with SANITY.io as the backend faster and easier - but it locks you in to a base set of data the themes require to successfully build. It is a tradeoff but one that is worth it for a lot of use cases.

Shadowed components

useSiteMetadata.js: This is heart of what allows this theme to function as this hook is used throughout all of the themes to source data like site title, logo, etc. Changing the source form gatsby-config to SANITY.io allows all of these components to be updated without having to actual change their code.

seo.js: This is shadowed to ensure that social images are sourced correctly.

gatsby-node.js

There is quite a bit going on in gatsby-node to manage the createPages api from Gatsby. Theme options are used to conditionally build pages in the build process - this means that if you want a blog on your site the “infrastructure” is there in gatsby-node to create the pages but can be turned on/off based on whether you need this feature. This results in some warnings in the build process because Gatsby.

Query components and template components

Queries and templates are separated to isolate visual components from data components. This is best practice in a Gatsby theme and means that in most cases you can just modify the visual layer through component shadowing and leave the data alone letting you concentrate on design.

These are located at src/components/queries/ and src/components/templates/.

You can see an example of this in use with gatsby-theme-catalyst-hydrogen.

Theme Options

OptionValuesDescription
sanityProjectIdStringRequired, Sanity project ID
sanityDatasetStringDefaults to “production”, change to reflect the dataset name you are using in Sanity
sanityTokenStringDefaults to null, should only be used with env variables for security purposes.
sanityWatchModeBooleanDefaults to true, toggle for watch mode
sanityOverlayDraftsBooleanDefaults to false, toggle for live previews, a token and private dataset is required.
sanityCreatePagesBooleanDefaults to true, toggle to turn on/off page generation from SANITY.io.
sanityCreatePostsBooleanDefaults to true, toggle to turn on/off blog post page generation from SANITY.io.
sanityCreatePostsListBooleanDefaults to true, toggle to turn on/off blog post list generation from SANITY.io.
sanityCreateProjectsBooleanDefaults to true, toggle to turn on/off project page generation from SANITY.io.
sanityCreateProjectsListBooleanDefaults to true, toggle to turn on/off project list generation from SANITY.io.
sanityPostPathStringDefaults to “/posts”, is the path for the posts index and also before posts, e.g. site.com/posts/post-1.
sanityProjectPathStringDefaults to “/projects”, is the path for the projects index and also before projects, e.g. site.com/projects/post-1.
useSanityThemeBooleanExperimental. Enables merging the theme-ui theme specification from SANITY.io allowing use of a GUI to change the site theme, e.g. colors.

© 2020 Gatsby Theme Catalyst