Sanity Schema
Sanity schema and building custome types
Sanity
Sanity is a fully customizable CMS with a default content studio which can be customizable with Reactjs.
Sanity headless CMS based on structured content. The use case of Sanity start with a minimal blog.
We can create custom types with Schema, and manage contents with Sanity studio. Contents can be only managed by the Studio.
Schema
Under the sanity-project/schema, we can define schema and exporting them as simple JavaScript object.
export default{
name:'author',
type:'document',
title:'Author',
fields:[
{
name:'name',
type:'string',
title:'Name'
}
]
}
The name of the the document type should be in lowercase. Every document can have set of fields, in studio these are form fields.
In the Schema.js, we should import them as
// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator'
import author from './author'
// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type'
// Then we give our schema to the builder and provide the result to Sanity
export default createSchema({
// We name our schema
name: 'default',
// Then proceed to concatenate our document type
// to the ones provided by any plugins that are installed
types: schemaTypes.concat([
author,
/* Your types here! */
]),
})
Sanity has variety of schema types .A document type can have array of types and custom objects and reference to other types.
Fore example such as Author in Post document.