Model Properties
Each defined model can be configured with a number of properties. These are detailed further in a separate document.
Visual Editor supports using files to store content (Git CMS). This guide covers what you need to know about configuring Visual Editor for a two-way data sync between Visual Editor and file-based content.
Here is a simplified example that defines the following:
page
model with a required title
field.content
directory as JSON files.public/images
directory.// stackbit.config.tsimport { defineStackbitConfig } from "@stackbit/types";import { GitContentSource } from "@stackbit/cms-git";
export default defineStackbitConfig({ stackbitVersion: "~0.6.0", contentSources: [ new GitContentSource({ rootPath: __dirname, contentDirs: ["content"], models: [ { name: "Page", type: "page", urlPath: "/{slug}", filePath: "content/pages/{slug}.json", fields: [{ name: "title", type: "string", required: true }] } ], assetsConfig: { referenceType: "static", staticDir: "public", uploadDir: "images", publicPath: "/" } }) ]});
The only thing required to work with Git CMS is to install the development dependencies.
npm install -D @stackbit/types @stackbit/cms-git
Git CMS is unique in that all content modeling must be done within content source configuration. The options to define the schema are documented below.
Note that when Visual Editor reads and writes content to your remote repository, it uses the repository URL and branch you define in Git when you configure your project. These values aren’t used in local development because Visual Editor writes content changes to disk when running locally.
assetsConfig
Defines where local site assets are stored in your project and how other content references these assets.
referenceType
: (required) specifies how content files reference asset files. Options: static
, relative
.uploadDir
: (required) path inside assetsDir
in which to store uploaded assets, relative to either staticDir
(for static
assets) or assetsDir
(for relative
assets).static
assets:
staticDir
: directory path relative to the project root in which the site framework copies files to the directory that get deployed.publicPath
: URL from which the static files are publicly available.relative
assets:
assetsDir
: path to the directory containing all the assets to your project, relative to the project root.Here’s an example configuration for this object using static assets from a public/images
directory.
// stackbit.config.tsexport default defineStackbitConfig({ contentSources: [ new GitContentSource({ assetsConfig: { referenceType: "static", staticDir: "public", uploadDir: "images", publicPath: "/" } // ... }) ]});
staticDir
, either directly or in subdirectories. They cannot be colocated with page content or source code. The value is always relative to the root of the project.publicPath
. The full URLs are constructed as {publicPath}/{file path under staticDir}
.public/images/image.png
in your repository will be served from the URL /images/image.png
.{staticDir}/{uploadDir}
, or in the above case: {root}/public/images
.When asset files are colocated with content, use relative
references.
// stackbit.config.tsexport default defineStackbitConfig({ contentSources: [ new GitContentSource({ assetsConfig: { referenceType: "relative", assetsDir: "src", uploadDir: "images" } // ... }) ]});
assetsDir
can include files of different types. However, only files with specific extensions will be treated as assets (png, jpg, jpeg, gif, svg, ico, etc.).{assetsDir}/{uploadDir}
, or in the above case: {root}/src/images
.contentDirs
Defines directories in which to look for content. Each document is mapped to a model using the value of the type
property.
// stackbit.config.tsexport default defineStackbitConfig({ contentSources: [ new GitContentSource({ contentDirs: ["content"] // ... }) ]});
models
This is your schema definition for all file-based content.
// stackbit.config.tsexport default defineStackbitConfig({ contentSources: [ new GitContentSource({ models: [ { name: "Page", type: "page", urlPath: "/{slug}", filePath: "content/pages/{slug}.json", fields: [{ name: "title", type: "string", required: true }] } // ... ] // ... }) ]});
Model Properties
Each defined model can be configured with a number of properties. These are detailed further in a separate document.
rootPath
Absolute path to the root of your project. This is used to build relative paths for other configuration properties.
// stackbit.config.tsexport default defineStackbitConfig({ contentSources: [ new GitContentSource({ rootPath: __dirname // ... }) ]});
When specifying object ID for annotations, most content sources will have an obvious ID value.
For Git CMS, this value is the path to the source file, relative to the root of the project, and including the file extension. For example, say a home page is located at content/pages/index.json
.
.└── content/ └── pages/ └── index.json
The ID value would be content/pages/index.json
.
<div data-sb-object-id="content/pages/index.json">...</div>
Your feedback helps us improve our docs.