Skip to content

Instantly share code, notes, and snippets.

@lowmess
Created July 26, 2021 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lowmess/f06523b572688972ab15bde0b1fcde3e to your computer and use it in GitHub Desktop.
Save lowmess/f06523b572688972ab15bde0b1fcde3e to your computer and use it in GitHub Desktop.
lameass.recipes schema
export default {
title: 'About Page',
name: 'about_page',
type: 'document',
fields: [
{
title: 'Title',
name: 'title',
type: 'string',
},
{
title: 'Content',
name: 'content',
type: 'text',
},
],
}
export default {
title: 'Category',
name: 'category',
type: 'document',
fields: [
{
title: 'Title',
name: 'title',
type: 'string',
validation: (Rule) => Rule.required(),
},
{
title: 'Slug',
name: 'slug',
type: 'slug',
validation: (Rule) => Rule.required(),
options: { source: 'title' },
},
{
title: 'Emoji',
description:
"This can't automatically be checked to be an emoji, but it should be one.",
name: 'emoji',
type: 'string',
validation: (Rule) => Rule.required().max(3),
},
],
}
export default {
title: 'Homepage',
name: 'homepage',
type: 'document',
fields: [
{
title: 'Headline',
name: 'headline',
type: 'string',
},
{
title: 'Featured Meal',
name: 'featured_meal',
type: 'reference',
to: [{ type: 'meal' }],
},
],
}
export default {
title: 'Meal',
name: 'meal',
type: 'document',
fieldsets: [
{
title: 'Info',
name: 'info',
options: {
columns: 2,
},
},
],
fields: [
{
title: 'Title',
name: 'title',
type: 'string',
validation: (Rule) => Rule.required(),
},
{
title: 'Slug',
name: 'slug',
type: 'slug',
validation: (Rule) => Rule.required(),
options: { source: 'title' },
},
{
title: 'Description',
description:
"If needed at all, this should be short and sweet. Remember our commitment: no storytime recipes, just down-to-brass-tacks good cookin'.",
name: 'description',
type: 'text',
rows: 4,
},
{
title: 'Prep Time',
description: 'Time to prep in minutes',
name: 'prep_time',
fieldset: 'info',
type: 'number',
validation: (Rule) => Rule.integer().positive(),
},
{
title: 'Cook Time',
description: 'Time to cook in minutes',
name: 'cook_time',
fieldset: 'info',
type: 'number',
validation: (Rule) => Rule.integer().positive(),
},
{
title: 'Yield Amount',
description: 'Should be serving size, e.g. "Serves 4-6"',
name: 'yield_amount',
fieldset: 'info',
type: 'string',
},
{
title: 'Recipes',
name: 'recipes',
type: 'array',
of: [
{
type: 'reference',
to: [{ type: 'recipe' }],
},
],
},
{
title: 'Direction Sections',
name: 'sections',
type: 'array',
of: [
{
type: 'section',
},
],
},
],
}
export default {
title: 'Section',
name: 'section',
type: 'object',
fields: [
{
type: 'Title',
name: 'title',
type: 'string',
},
{
title: 'Steps',
name: 'steps',
type: 'array',
of: [
{
type: 'text',
rows: 1,
},
],
},
],
}
export default {
title: 'Recipe',
name: 'recipe',
type: 'document',
fieldsets: [
{
title: 'Taxonomy',
name: 'taxonomy',
},
{
title: 'Info',
name: 'info',
options: {
columns: 2,
},
},
{
title: 'Recipe',
name: 'recipe',
},
],
fields: [
{
title: 'Title',
name: 'title',
type: 'string',
validation: (Rule) => Rule.required(),
},
{
title: 'Slug',
name: 'slug',
type: 'slug',
validation: (Rule) => Rule.required(),
options: { source: 'title' },
},
{
title: 'Description',
description:
"If needed at all, this should be short and sweet. Remember our commitment: no storytime recipes, just down-to-brass-tacks good cookin'.",
name: 'description',
type: 'text',
rows: 4,
},
{
title: 'Category',
name: 'category',
fieldset: 'taxonomy',
type: 'reference',
to: [{ type: 'category' }],
validation: (Rule) => Rule.required(),
},
{
title: 'Tags',
name: 'tags',
fieldset: 'taxonomy',
type: 'array',
of: [{ type: 'reference', to: [{ type: 'tag' }] }],
},
{
title: 'Prep Time',
description: 'Time to prep in minutes',
name: 'prep_time',
fieldset: 'info',
type: 'number',
validation: (Rule) => Rule.integer().positive(),
},
{
title: 'Cook Time',
description: 'Time to cook in minutes',
name: 'cook_time',
fieldset: 'info',
type: 'number',
validation: (Rule) => Rule.integer().positive(),
},
{
title: 'Yield Amount',
name: 'yield_amount',
fieldset: 'info',
type: 'string',
},
{
title: 'Yield Type',
name: 'yield_type',
fieldset: 'info',
type: 'string',
options: {
list: [
{ title: 'Servings', value: 'servings' },
{ title: 'Amount', value: 'amount' },
],
},
},
{
title: 'Equipment',
name: 'equipment',
fieldset: 'recipe',
type: 'array',
of: [{ type: 'string' }],
},
{
title: 'Ingredients',
name: 'ingredients',
fieldset: 'recipe',
type: 'array',
of: [{ type: 'string' }],
},
{
title: 'Direction Sections',
name: 'sections',
fieldset: 'recipe',
type: 'array',
of: [
{
type: 'section',
},
],
},
{
title: 'Notes',
name: 'notes',
fieldset: 'recipe',
type: 'text',
rows: 4,
},
{
title: 'Search Terms',
description:
'Search terms separated by spaces. Capitalization and punctuation are automatically ignored. Recipe title, category, and tags are already indexed for search.',
name: 'search_terms',
type: 'string',
},
],
initialValue: {
yield_type: 'servings',
},
}
// First, we must import the schema creator
import createSchema from 'part:@sanity/base/schema-creator'
// Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type'
import homepage from './homepage'
import about from './about-page'
import meal from './meal'
import recipe from './recipe'
import section from './recipe-section'
import category from './category'
import tag from './tag'
// 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([
/* Your types here! */
homepage,
about,
meal,
recipe,
section,
category,
tag,
]),
})
export default {
title: 'Tag',
name: 'tag',
type: 'document',
fields: [
{
title: 'Title',
name: 'title',
type: 'string',
validation: (Rule) => Rule.required(),
},
{
title: 'Slug',
name: 'slug',
type: 'slug',
validation: (Rule) => Rule.required(),
options: { source: 'title' },
},
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment