How to work with Sanity CMS
Learn Sanity
If you are new to Sanity, you can learn it from the Sanity Courses, especially the following two courses:
These courses are free and will help you understand how to use Sanity, and the following content are based on these courses.
Add or update the Sanity schema
The Sanity schema files are in the src/sanity/schemas/documents
folder, you can change the schema to your own schema, or add new schema, then add the new schema to the src/sanity/schemas/index.ts
file.
After you update the Sanity schema, you need to run the following command to generate the types:
For example, you want to add a new field to the item
schema, you can add the new field to the src/sanity/schemas/documents/directory/item.ts
file, and then update the itemSimpleFields
in the src/sanity/libs/queries.ts
file, so that the new field will be fetched from the Sanity CMS when you query the item information from the GROQ queries.
Update the GROQ queries
The GROQ queries are in the src/sanity/lib/queries.ts
file, you can change the GROQ queries to your own queries, or add new queries to the file.
After you update the GROQ queries, you need to run the following command to generate the types:
Configure the Sanity Studio
The configuration of the Sanity Studio is in the sanity.config.ts
file, you can customize the Sanity Studio to your own needs.
For example, you can find a new Sanity Plugin and add it to the Sanity Studio.
You can also change the default layout structure, according to the Sanity Structure Builder.