Skip to content

Commit

Permalink
leave posts in
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhooks authored and kodiakhq[bot] committed Nov 22, 2023
1 parent 0c8891b commit 0dcc350
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions apps/course-builder-web/sanity/schemas/documents/post.ts
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(' ')}
},
},
})

1 comment on commit 0dcc350

@vercel
Copy link

@vercel vercel bot commented on 0dcc350 Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.