-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c8891b
commit 0dcc350
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {BookIcon} from '@sanity/icons' | ||
import {format, parseISO} from 'date-fns' | ||
import {defineField, defineType} from 'sanity' | ||
|
||
import authorType from './author' | ||
|
||
/** | ||
* This file is the schema definition for a post. | ||
* | ||
* Here you'll be able to edit the different fields that appear when you | ||
* create or edit a post in the studio. | ||
* | ||
* Here you can see the different schema types that are available: | ||
https://www.sanity.io/docs/schema-types | ||
*/ | ||
|
||
export default defineType({ | ||
name: 'post', | ||
title: 'Post', | ||
icon: BookIcon, | ||
type: 'document', | ||
fields: [ | ||
defineField({ | ||
name: 'title', | ||
title: 'Title', | ||
type: 'string', | ||
validation: (rule) => rule.required(), | ||
}), | ||
defineField({ | ||
name: 'slug', | ||
title: 'Slug', | ||
type: 'slug', | ||
options: { | ||
source: 'title', | ||
maxLength: 96, | ||
isUnique: (value, context) => context.defaultIsUnique(value, context), | ||
}, | ||
validation: (rule) => rule.required(), | ||
}), | ||
defineField({ | ||
name: 'content', | ||
title: 'Content', | ||
type: 'markdown', | ||
}), | ||
defineField({ | ||
name: 'excerpt', | ||
title: 'Excerpt', | ||
type: 'text', | ||
}), | ||
defineField({ | ||
name: 'coverImage', | ||
title: 'Cover Image', | ||
type: 'image', | ||
options: { | ||
hotspot: true, | ||
}, | ||
}), | ||
defineField({ | ||
name: 'date', | ||
title: 'Date', | ||
type: 'datetime', | ||
initialValue: () => new Date().toISOString(), | ||
}), | ||
defineField({ | ||
name: 'author', | ||
title: 'Author', | ||
type: 'reference', | ||
to: [{type: authorType.name}], | ||
}), | ||
defineField({ | ||
name: 'resources', | ||
title: 'Resources', | ||
type: 'array', | ||
of: [{type: 'reference', to: [{type: 'videoResource'}]}], | ||
}), | ||
], | ||
preview: { | ||
select: { | ||
title: 'title', | ||
author: 'author.name', | ||
date: 'date', | ||
media: 'coverImage', | ||
}, | ||
prepare({title, media, author, date}) { | ||
const subtitles = [ | ||
author && `by ${author}`, | ||
date && `on ${format(parseISO(date), 'LLL d, yyyy')}`, | ||
].filter(Boolean) | ||
|
||
return {title, media, subtitle: subtitles.join(' ')} | ||
}, | ||
}, | ||
}) |
0dcc350
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
course-builder-docs – ./docs
course-builder-docs-skillrecordings.vercel.app
docs.coursebuilder.dev
course-builder-docs-git-main-skillrecordings.vercel.app
course-builder-docs.vercel.app