How to create schema for series episodes with multiple URL fields in Sanity?
49 replies
Last updated: Dec 6, 2022
AI Update
You'll want to use an array field with object members for your episode schema! This is perfect for your use case where each episode needs multiple streaming links.
Here's how to structure your series schema:
import {defineType, defineField, defineArrayMember} from 'sanity'
export default defineType({
name: 'series',
title: 'Series',
type: 'document',
fields: [
defineField({
name: 'title',
title: 'Series Title',
type: 'string',
}),
defineField({
name: 'seasons',
title: 'Seasons',
type: 'array',
of: [
defineArrayMember({
type: 'object',
name: 'season',
title: 'Season',
fields: [
{
name: 'seasonNumber',
title: 'Season Number',
type: 'number',
},
{
name: 'episodes',
title: 'Episodes',
type: 'array',
of: [
defineArrayMember({
type: 'object',
name: 'episode',
title: 'Episode',
fields: [
{
name: 'episodeNumber',
title: 'Episode Number',
type: 'number',
},
{
name: 'title',
title: 'Episode Title',
type: 'string',
},
{
name: 'streamingLinks',
title: 'Streaming Links',
type: 'array',
of: [
defineArrayMember({
type: 'object',
name: 'link',
fields: [
{
name: 'url',
title: 'URL',
type: 'url',
},
{
name: 'platform',
title: 'Platform Name',
type: 'string',
description: 'e.g., Netflix, Prime Video, etc.'
},
{
name: 'quality',
title: 'Quality',
type: 'string',
options: {
list: ['720p', '1080p', '4K']
}
}
],
preview: {
select: {
title: 'platform',
subtitle: 'url'
}
}
})
]
}
],
preview: {
select: {
title: 'title',
episode: 'episodeNumber'
},
prepare({title, episode}) {
return {
title: `Episode ${episode}: ${title}`
}
}
}
})
]
}
],
preview: {
select: {
season: 'seasonNumber'
},
prepare({season}) {
return {
title: `Season ${season}`
}
}
}
})
]
})
]
})This schema gives you:
- Nested arrays - Series → Seasons → Episodes → Streaming Links
- The + button you want - Array fields automatically provide the "Add item" button for adding multiple URLs
- Custom previews - So you can see episode titles and platform names at a glance without opening each item
- Flexible link structure - Each episode can have as many streaming links as needed
In the Studio, users will:
- Click the + button next to "Streaming Links"
- Add a URL, platform name, and quality for each link
- Keep clicking + to add more links to that episode
You can also add validation if needed (like requiring at least one streaming link per episode):
{
name: 'streamingLinks',
title: 'Streaming Links',
type: 'array',
validation: Rule => Rule.required().min(1).error('At least one streaming link is required'),
of: [...]
}The array field documentation has more details on customization options if you want to enhance the UI further!
Show original thread49 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.