Skip to content

Instantly share code, notes, and snippets.

@kmelve
Created February 13, 2020 21:52
Show Gist options
  • Save kmelve/24803c15ed01d99d102dda7a5f450c72 to your computer and use it in GitHub Desktop.
Save kmelve/24803c15ed01d99d102dda7a5f450c72 to your computer and use it in GitHub Desktop.
Preview conf with referenced doc
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([
{
name: 'frontpage',
type: 'document',
title: 'Frontpage',
fields: [
{
name: 'title',
type: 'string',
},
{
name: 'layouts',
type: 'layouts',
},
],
preview: {
select: {
// this lets you access the title in the referenced
articleInFirstLayoutTitle: 'layouts.0.article.title',
articleImage: 'layouts.0.article.image',
},
prepare(selection) {
console.log({ selection });
const {
// articleInFirstLayout,
articleInFirstLayoutTitle,
articleImage,
} = selection;
return {
title: articleInFirstLayoutTitle, // undefined
media: articleImage, // undefined
};
},
},
},
{
name: 'layouts',
type: 'array',
of: [
{
type: 'layout',
},
],
},
{
name: 'layout',
type: 'object',
fields: [
{
name: 'title',
type: 'string',
},
{
name: 'article',
type: 'reference',
to: [{ type: 'article' }],
},
],
},
{
name: 'article',
type: 'document',
title: 'Article',
fields: [
{
name: 'title',
type: 'string',
},
{
name: 'image',
type: 'image',
},
],
},
]),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment