Schema
Subject: Create a schema in Sanity.io
Ship Ahoy Skill Builder!
My tiny task this Sunday is:
- Make it doable for my daughter Lillian (6 🏴☠️ 👸 ) to:
- Upload images of Lillian’s drawings from my data-machine to my Sanity.io on http://localhost:3333/desk/pizza 🖼️
- Name images of Lillian’s drawings, for example this one:
What will I do?
- Create a schema in Sanity.io
- Add my schema to schema.js
Why will I do it?
I was working on my personal website. I got the idea to show images of Lillian’s projects and drawings. Why is adding Lillian’s projects and drawings to my website making my skill building better? Join us live or check out the recording of our podcast here to find out: https://www.youtube.com/watch?v=4nWUMgiEpdc
How will I do it?
The Steps
- 😼
In
sanity / schemas
make a new pirate-schema-file:papasPiratyPizzas.js
Insanity / schemas / schema.js
addimport papasPiratyPizzas from './papasPiratyPizzas';
Insanity / schemas / schema.js
addpapasPiratyPizzas
inside your.con-😼 ([]),
on line 16
Save and run your code Look at your localhost
- 🍕
Write an object:
export default {};
Give it thetype: 'document',
Name it'pizza',
Save and run your code Look at your localhost
- 🗻
Write an array:
fields: [];
Write an object and give it thetype: 'string',
and name it'name',
Save and run your code Go to localhost and look inside BeepBoop
- 🖼️
Write an object and give it the
type: 'image',
and name it'image',
Save and run your code Go to localhost and look inside BeepBoop Finished 🏴☠️ 😸 👍
🔧😺👍
Keep your skill-building-submarine afloat this week! 🔧⛵🏴☠️
Ola Vea Gatsby Piraty Captain
P.S.
Finished code:
//sanity / schemas / papasPiratyPizzas.js
export default {
name: 'pizza',
// Type of Pirate Schema
type: 'document',
fields: [
{
name: 'name',
type: 'string',
},
{
name: 'image',
type: 'image',
},
],
};
//sanity / schemas / schema.js
....
import papasPiratyPizzas from './papasPiratyPizzas';
export default createSchema({
name: 'default',
// con-😼 is here 🔽
types: schemaTypes.concat([papasPiratyPizzas]),
});