Unverified Commit 0c7217ba authored by Cody Olsen's avatar Cody Olsen Committed by GitHub

docs(examples): use vercel integration in cms-sanity (#39323)

## Feature

- [x] Documentation added

## Documentation / Examples

- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

This PR updates the cms-sanity example to:
- Deploy to Vercel with the [Sanity Vercel Integration](https://www.sanity.io/docs/vercel-integration) by default.
- You can still opt-out of using the Sanity Vercel Integration, clicking `You can also set up manually` gives you all the information you need.
- The blog itself is updated so it's much more resilient to missing data, and is setup to set `revalidate: 60` until you have a On-demand Revalidation webhook setup.
- Preview Mode is now enabled on the frontpage as well.
- The Sanity client setup, and webhook validation, are updated to follow our current best practices.
parent 911ba233
NEXT_PUBLIC_SANITY_PROJECT_ID= NEXT_PUBLIC_SANITY_PROJECT_ID=
NEXT_PUBLIC_SANITY_DATASET= NEXT_PUBLIC_SANITY_DATASET=
SANITY_API_TOKEN= SANITY_API_READ_TOKEN=
SANITY_PREVIEW_SECRET=
SANITY_STUDIO_REVALIDATE_SECRET=
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# dependencies # dependencies
/node_modules /node_modules
/studio/node_modules
/.pnp /.pnp
.pnp.js .pnp.js
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
# production # production
/build /build
/studio/dist
# misc # misc
.DS_Store .DS_Store
...@@ -34,3 +36,7 @@ yarn-error.log* ...@@ -34,3 +36,7 @@ yarn-error.log*
# typescript # typescript
*.tsbuildinfo *.tsbuildinfo
next-env.d.ts next-env.d.ts
# Env files created by scripts for working locally
.env
studio/.env.development
\ No newline at end of file
This diff is collapsed.
import Image from 'next/image' import Image from 'next/future/image'
import { urlForImage } from '../lib/sanity' import { urlForImage } from '../lib/sanity'
export default function Avatar({ name, picture }) { export default function Avatar({ name, picture }) {
return ( return (
<div className="flex items-center"> <div className="flex items-center">
<div className="w-12 h-12 relative mr-4"> <div className="relative w-12 h-12 mr-4">
<Image <Image
src={urlForImage(picture).height(96).width(96).fit('crop').url()} src={
layout="fill" picture?.asset?._ref
? urlForImage(picture).height(96).width(96).fit('crop').url()
: 'https://source.unsplash.com/96x96/?face'
}
className="rounded-full" className="rounded-full"
height={96}
width={96}
alt={name} alt={name}
/> />
</div> </div>
......
import cn from 'classnames' import cn from 'classnames'
import Image from 'next/image' import Image from 'next/future/image'
import Link from 'next/link' import Link from 'next/link'
import { urlForImage } from '../lib/sanity' import { urlForImage } from '../lib/sanity'
export default function CoverImage({ title, slug, image: source }) { export default function CoverImage({ title, slug, image: source, priority }) {
const image = source ? ( const image = source?.asset?._ref ? (
<div <div
className={cn('shadow-small', { className={cn('shadow-small', {
'hover:shadow-medium transition-shadow duration-200': slug, 'hover:shadow-medium transition-shadow duration-200': slug,
})} })}
> >
<Image <Image
className="w-full h-auto"
layout="responsive" layout="responsive"
width={2000} width={2000}
height={1000} height={1000}
alt={`Cover Image for ${title}`} alt={`Cover Image for ${title}`}
src={urlForImage(source).height(1000).width(2000).url()} src={urlForImage(source).height(1000).width(2000).url()}
sizes="100vw"
priority={priority}
/> />
</div> </div>
) : ( ) : (
......
import { parseISO, format } from 'date-fns' import { parseISO, format } from 'date-fns'
export default function Date({ dateString }) { export default function Date({ dateString }) {
if (!dateString) return null
const date = parseISO(dateString) const date = parseISO(dateString)
return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time> return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>
} }
...@@ -14,22 +14,22 @@ export default function HeroPost({ ...@@ -14,22 +14,22 @@ export default function HeroPost({
return ( return (
<section> <section>
<div className="mb-8 md:mb-16"> <div className="mb-8 md:mb-16">
<CoverImage slug={slug} title={title} image={coverImage} /> <CoverImage slug={slug} title={title} image={coverImage} priority />
</div> </div>
<div className="md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8 mb-20 md:mb-28"> <div className="mb-20 md:grid md:grid-cols-2 md:gap-x-16 lg:gap-x-8 md:mb-28">
<div> <div>
<h3 className="mb-4 text-4xl lg:text-6xl leading-tight"> <h3 className="mb-4 text-4xl leading-tight lg:text-6xl">
<Link href={`/posts/${slug}`}> <Link href={`/posts/${slug}`}>
<a className="hover:underline">{title}</a> <a className="hover:underline">{title}</a>
</Link> </Link>
</h3> </h3>
<div className="mb-4 md:mb-0 text-lg"> <div className="mb-4 text-lg md:mb-0">
<Date dateString={date} /> <Date dateString={date} />
</div> </div>
</div> </div>
<div> <div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p> <p className="mb-4 text-lg leading-relaxed">{excerpt}</p>
<Avatar name={author.name} picture={author.picture} /> {author && <Avatar name={author.name} picture={author.picture} />}
</div> </div>
</div> </div>
</section> </section>
......
...@@ -8,14 +8,14 @@ export default function PostHeader({ title, coverImage, date, author }) { ...@@ -8,14 +8,14 @@ export default function PostHeader({ title, coverImage, date, author }) {
<> <>
<PostTitle>{title}</PostTitle> <PostTitle>{title}</PostTitle>
<div className="hidden md:block md:mb-12"> <div className="hidden md:block md:mb-12">
<Avatar name={author.name} picture={author.picture} /> {author && <Avatar name={author.name} picture={author.picture} />}
</div> </div>
<div className="mb-8 md:mb-16 sm:mx-0"> <div className="mb-8 md:mb-16 sm:mx-0">
<CoverImage title={title} image={coverImage} /> <CoverImage title={title} image={coverImage} priority />
</div> </div>
<div className="max-w-2xl mx-auto"> <div className="max-w-2xl mx-auto">
<div className="block md:hidden mb-6"> <div className="block mb-6 md:hidden">
<Avatar name={author.name} picture={author.picture} /> {author && <Avatar name={author.name} picture={author.picture} />}
</div> </div>
<div className="mb-6 text-lg"> <div className="mb-6 text-lg">
<Date dateString={date} /> <Date dateString={date} />
......
...@@ -16,16 +16,16 @@ export default function PostPreview({ ...@@ -16,16 +16,16 @@ export default function PostPreview({
<div className="mb-5"> <div className="mb-5">
<CoverImage slug={slug} title={title} image={coverImage} /> <CoverImage slug={slug} title={title} image={coverImage} />
</div> </div>
<h3 className="text-3xl mb-3 leading-snug"> <h3 className="mb-3 text-3xl leading-snug">
<Link href={`/posts/${slug}`}> <Link href={`/posts/${slug}`}>
<a className="hover:underline">{title}</a> <a className="hover:underline">{title}</a>
</Link> </Link>
</h3> </h3>
<div className="text-lg mb-4"> <div className="mb-4 text-lg">
<Date dateString={date} /> <Date dateString={date} />
</div> </div>
<p className="text-lg leading-relaxed mb-4">{excerpt}</p> <p className="mb-4 text-lg leading-relaxed">{excerpt}</p>
<Avatar name={author.name} picture={author.picture} /> {author && <Avatar name={author.name} picture={author.picture} />}
</div> </div>
) )
} }
...@@ -2,13 +2,14 @@ export const sanityConfig = { ...@@ -2,13 +2,14 @@ export const sanityConfig = {
// Find your project ID and dataset in `sanity.json` in your studio project // Find your project ID and dataset in `sanity.json` in your studio project
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production', dataset: process.env.NEXT_PUBLIC_SANITY_DATASET || 'production',
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID, projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
useCdn: process.env.NODE_ENV !== 'production', useCdn:
typeof document !== 'undefined' && process.env.NODE_ENV === 'production',
// useCdn == true gives fast, cheap responses using a globally distributed cache. // useCdn == true gives fast, cheap responses using a globally distributed cache.
// When in production the Sanity API is only queried on build-time, and on-demand when responding to webhooks. // When in production the Sanity API is only queried on build-time, and on-demand when responding to webhooks.
// Thus the data need to be fresh and API response time is less important. // Thus the data need to be fresh and API response time is less important.
// When in development/working locally, it's more important to keep costs down as hot reloading can incurr a lot of API calls // When in development/working locally, it's more important to keep costs down as hot reloading can incurr a lot of API calls
// And every page load calls getStaticProps. // And every page load calls getStaticProps.
// To get the lowest latency, lowest cost, and latest data, use the Instant Preview mode // To get the lowest latency, lowest cost, and latest data, use the Instant Preview mode
apiVersion: '2021-03-25', apiVersion: '2022-03-13',
// see https://www.sanity.io/docs/api-versioning for how versioning works // see https://www.sanity.io/docs/api-versioning for how versioning works
} }
...@@ -11,7 +11,10 @@ export const sanityClient = createClient(sanityConfig) ...@@ -11,7 +11,10 @@ export const sanityClient = createClient(sanityConfig)
export const previewClient = createClient({ export const previewClient = createClient({
...sanityConfig, ...sanityConfig,
useCdn: false, useCdn: false,
token: process.env.SANITY_API_TOKEN, // Fallback to using the WRITE token until https://www.sanity.io/docs/vercel-integration starts shipping a READ token.
// As this client only exists on the server and the token is never shared with the browser, we ddon't risk escalating permissions to untrustworthy users
token:
process.env.SANITY_API_READ_TOKEN || process.env.SANITY_API_WRITE_TOKEN,
}) })
export const getClient = (preview) => (preview ? previewClient : sanityClient) export const getClient = (preview) => (preview ? previewClient : sanityClient)
......
module.exports = { module.exports = {
experimental: {
images: {
allowFutureImage: true,
},
},
images: { images: {
domains: ['cdn.sanity.io'], domains: ['cdn.sanity.io', 'source.unsplash.com'],
}, },
} }
...@@ -3,22 +3,24 @@ ...@@ -3,22 +3,24 @@
"scripts": { "scripts": {
"dev": "next", "dev": "next",
"build": "next build", "build": "next build",
"start": "next start" "start": "next start",
"studio:dev": "npm --prefix studio run start",
"studio:deploy": "npx vercel env pull && npm --prefix studio run deploy"
}, },
"dependencies": { "dependencies": {
"@portabletext/react": "^1.0.3", "@portabletext/react": "^1.0.6",
"@sanity/image-url": "^1.0.1", "@sanity/image-url": "^1.0.1",
"@sanity/webhook": "^1.0.2", "@sanity/webhook": "^2.0.0",
"classnames": "2.3.1", "classnames": "^2.3.1",
"date-fns": "2.28.0", "date-fns": "^2.29.1",
"next": "latest", "next": "latest",
"next-sanity": "0.5.0", "next-sanity": "^0.6.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2" "react-dom": "^17.0.2"
}, },
"devDependencies": { "devDependencies": {
"autoprefixer": "10.4.2", "autoprefixer": "^10.4.8",
"postcss": "8.4.7", "postcss": "^8.4.14",
"tailwindcss": "^3.0.23" "tailwindcss": "^3.1.7"
} }
} }
import { postBySlugQuery } from '../../lib/queries' import { postBySlugQuery } from '../../lib/queries'
import { previewClient } from '../../lib/sanity.server' import { previewClient } from '../../lib/sanity.server'
function redirectToPreview(res, Location) {
// Enable Preview Mode by setting the cookies
res.setPreviewData({})
// Redirect to a preview capable route
res.writeHead(307, { Location })
res.end()
}
export default async function preview(req, res) { export default async function preview(req, res) {
// Check the secret and next parameters const secret = process.env.SANITY_STUDIO_PREVIEW_SECRET
// This secret should only be known to this API route and the CMS // Only require a secret when in production
if ( if (!secret && process.env.NODE_ENV === 'production') {
req.query.secret !== process.env.SANITY_PREVIEW_SECRET || throw new TypeError(`Missing SANITY_STUDIO_PREVIEW_SECRET`)
!req.query.slug }
) { // Check the secret if it's provided, enables running preview mode locally before the env var is setup
return res.status(401).json({ message: 'Invalid token' }) if (secret && req.query.secret !== secret) {
return res.status(401).json({ message: 'Invalid secret' })
}
// If no slug is provided open preview mode on the frontpage
if (!req.query.slug) {
return redirectToPreview(res, '/')
} }
// Check if the post with the given `slug` exists // Check if the post with the given `slug` exists
...@@ -21,11 +34,7 @@ export default async function preview(req, res) { ...@@ -21,11 +34,7 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies
res.setPreviewData({})
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
res.writeHead(307, { Location: `/posts/${post.slug}` }) redirectToPreview(res, `/posts/${post.slug}`)
res.end()
} }
import { isValidRequest } from '@sanity/webhook' import { isValidSignature, SIGNATURE_HEADER_NAME } from '@sanity/webhook'
import { sanityClient } from '../../lib/sanity.server' import { sanityClient } from '../../lib/sanity.server'
const AUTHOR_UPDATED_QUERY = ` // Next.js will by default parse the body, which can lead to invalid signatures
export const config = {
api: {
bodyParser: false,
},
}
const AUTHOR_UPDATED_QUERY = /* groq */ `
*[_type == "author" && _id == $id] { *[_type == "author" && _id == $id] {
"slug": *[_type == "post" && references(^._id)].slug.current "slug": *[_type == "post" && references(^._id)].slug.current
}["slug"][]` }["slug"][]`
const POST_UPDATED_QUERY = `*[_type == "post" && _id == $id].slug.current` const POST_UPDATED_QUERY = /* groq */ `*[_type == "post" && _id == $id].slug.current`
const getQueryForType = (type) => { const getQueryForType = (type) => {
switch (type) { switch (type) {
...@@ -21,14 +28,32 @@ const getQueryForType = (type) => { ...@@ -21,14 +28,32 @@ const getQueryForType = (type) => {
const log = (msg, error) => const log = (msg, error) =>
console[error ? 'error' : 'log'](`[revalidate] ${msg}`) console[error ? 'error' : 'log'](`[revalidate] ${msg}`)
async function readBody(readable) {
const chunks = []
for await (const chunk of readable) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
}
return Buffer.concat(chunks).toString('utf8')
}
export default async function revalidate(req, res) { export default async function revalidate(req, res) {
if (!isValidRequest(req, process.env.SANITY_STUDIO_REVALIDATE_SECRET)) { const signature = req.headers[SIGNATURE_HEADER_NAME]
const invalidRequest = 'Invalid request' const body = await readBody(req) // Read the body into a string
log(invalidRequest, true) if (
return res.status(401).json({ message: invalidRequest }) !isValidSignature(
body,
signature,
process.env.SANITY_REVALIDATE_SECRET?.trim()
)
) {
const invalidSignature = 'Invalid signature'
log(invalidSignature, true)
res.status(401).json({ success: false, message: invalidSignature })
return
} }
const { _id: id, _type } = req.body const jsonBody = JSON.parse(body)
const { _id: id, _type } = jsonBody
if (typeof id !== 'string' || !id) { if (typeof id !== 'string' || !id) {
const invalidId = 'Invalid _id' const invalidId = 'Invalid _id'
log(invalidId, true) log(invalidId, true)
......
...@@ -6,11 +6,15 @@ import Intro from '../components/intro' ...@@ -6,11 +6,15 @@ import Intro from '../components/intro'
import Layout from '../components/layout' import Layout from '../components/layout'
import { CMS_NAME } from '../lib/constants' import { CMS_NAME } from '../lib/constants'
import { indexQuery } from '../lib/queries' import { indexQuery } from '../lib/queries'
import { usePreviewSubscription } from '../lib/sanity'
import { getClient, overlayDrafts } from '../lib/sanity.server' import { getClient, overlayDrafts } from '../lib/sanity.server'
export default function Index({ allPosts, preview }) { export default function Index({ allPosts: initialAllPosts, preview }) {
const heroPost = allPosts[0] const { data: allPosts } = usePreviewSubscription(indexQuery, {
const morePosts = allPosts.slice(1) initialData: initialAllPosts,
enabled: preview,
})
const [heroPost, ...morePosts] = allPosts || []
return ( return (
<> <>
<Layout preview={preview}> <Layout preview={preview}>
...@@ -40,5 +44,7 @@ export async function getStaticProps({ preview = false }) { ...@@ -40,5 +44,7 @@ export async function getStaticProps({ preview = false }) {
const allPosts = overlayDrafts(await getClient(preview).fetch(indexQuery)) const allPosts = overlayDrafts(await getClient(preview).fetch(indexQuery))
return { return {
props: { allPosts, preview }, props: { allPosts, preview },
// If webhooks isn't setup then attempt to re-generate in 1 minute intervals
revalidate: process.env.SANITY_REVALIDATE_SECRET ? undefined : 60,
} }
} }
...@@ -43,7 +43,7 @@ export default function Post({ data = {}, preview }) { ...@@ -43,7 +43,7 @@ export default function Post({ data = {}, preview }) {
<title> <title>
{post.title} | Next.js Blog Example with {CMS_NAME} {post.title} | Next.js Blog Example with {CMS_NAME}
</title> </title>
{post.coverImage && ( {post.coverImage?.asset?._ref && (
<meta <meta
key="ogImage" key="ogImage"
property="og:image" property="og:image"
...@@ -85,6 +85,8 @@ export async function getStaticProps({ params, preview = false }) { ...@@ -85,6 +85,8 @@ export async function getStaticProps({ params, preview = false }) {
morePosts: overlayDrafts(morePosts), morePosts: overlayDrafts(morePosts),
}, },
}, },
// If webhooks isn't setup then attempt to re-generate in 1 minute intervals
revalidate: process.env.SANITY_REVALIDATE_SECRET ? undefined : 60,
} }
} }
......
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/dist
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# local env files
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
\ No newline at end of file
{
"#": "Used by Sanity to keep track of configuration file checksums, do not delete or modify!",
"@sanity/default-layout": "bb034f391ba508a6ca8cd971967cbedeb131c4d19b17b28a0895f32db5d568ea",
"@sanity/default-login": "e2ed4e51e97331c0699ba7cf9f67cbf76f1c6a5f806d6eabf8259b2bcb5f1002",
"@sanity/form-builder": "b38478227ba5e22c91981da4b53436df22e48ff25238a55a973ed620be5068aa",
"@sanity/data-aspects": "d199e2c199b3e26cd28b68dc84d7fc01c9186bf5089580f2e2446994d36b3cb6",
"@sanity/vision": "da5b6ed712703ecd04bf4df560570c668aa95252c6bc1c41d6df1bda9b8b8f60"
}
{
"toolSwitcher": {
"order": [],
"hidden": []
}
}
{
"providers": {
"mode": "append",
"redirectOnSingle": false,
"entries": []
},
"loginMethod": "dual"
}
{
"defaultApiVersion": "2022-03-13"
}
{
"private": true,
"scripts": {
"start": "npx @sanity/cli start",
"deploy": "npx @sanity/cli deploy",
"cors:add": "npx @sanity/cli cors add",
"prestart": "npm run env",
"precors:add": "npm run env",
"predeploy": "npm run env",
"env": "npx @sanity/cli install && cp ../.env .env.development || cp ../.env.local .env.development"
},
"dependencies": {
"@sanity/base": "^2.30.1",
"@sanity/core": "^2.30.2",
"@sanity/default-layout": "^2.30.1",
"@sanity/default-login": "^2.30.1",
"@sanity/desk-tool": "^2.30.1",
"@sanity/production-preview": "2.29.3",
"@sanity/vision": "^2.30.1",
"prop-types": "^15.7",
"react": "^17.0",
"react-dom": "^17.0",
"sanity-plugin-asset-source-unsplash": "0.2.1",
"styled-components": "^5.2.0"
}
}
User-specific packages can be placed here
let productionUrl
try {
productionUrl = new URL(
process.env.SANITY_STUDIO_PREVIEW_URL || 'http://localhost:3000'
)
} catch (err) {
console.error('Invalid productionUrl', err)
}
export default function resolveProductionUrl(document) {
if (!productionUrl || !document.slug?.current) {
return false
}
const searchParams = new URLSearchParams()
searchParams.set('secret', process.env.SANITY_STUDIO_PREVIEW_SECRET || '')
searchParams.set('slug', document.slug.current)
return `${productionUrl.origin}/api/preview?${searchParams}`
}
{
"root": true,
"project": {
"name": "Blog"
},
"plugins": [
"@sanity/base",
"@sanity/default-layout",
"@sanity/default-login",
"@sanity/desk-tool",
"asset-source-unsplash",
"@sanity/production-preview"
],
"env": {
"development": {
"plugins": ["@sanity/vision"]
}
},
"parts": [
{
"name": "part:@sanity/base/schema",
"path": "./schemas/schema"
},
{
"implements": "part:@sanity/production-preview/resolve-production-url",
"path": "./resolveProductionUrl.js"
}
]
}
export default {
name: 'author',
title: 'Author',
type: 'document',
fields: [
{
name: 'name',
title: 'Name',
type: 'string',
validation: (Rule) => Rule.required(),
},
{
name: 'picture',
title: 'Picture',
type: 'image',
options: { hotspot: true },
validation: (Rule) => Rule.required(),
},
],
}
export default {
name: 'post',
title: 'Post',
type: 'document',
fields: [
{
name: 'title',
title: 'Title',
type: 'string',
validation: (Rule) => Rule.required(),
},
{
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
maxLength: 96,
},
validation: (Rule) => Rule.required(),
},
{
name: 'content',
title: 'Content',
type: 'array',
of: [{ type: 'block' }],
},
{
name: 'excerpt',
title: 'Excerpt',
type: 'string',
},
{
name: 'coverImage',
title: 'Cover Image',
type: 'image',
options: {
hotspot: true,
},
},
{
name: 'date',
title: 'Date',
type: 'datetime',
},
{
name: 'author',
title: 'Author',
type: 'reference',
to: [{ type: 'author' }],
},
],
preview: {
select: {
title: 'title',
author: 'author.name',
media: 'coverImage',
},
prepare(selection) {
const { author } = selection
return { ...selection, subtitle: author && `by ${author}` }
},
},
}
...@@ -4,6 +4,11 @@ import createSchema from 'part:@sanity/base/schema-creator' ...@@ -4,6 +4,11 @@ import createSchema from 'part:@sanity/base/schema-creator'
// Then import schema types from any plugins that might expose them // Then import schema types from any plugins that might expose them
import schemaTypes from 'all:part:@sanity/base/schema-type' import schemaTypes from 'all:part:@sanity/base/schema-type'
// We import object and document schemas
// import blockContent from './blockContent'
import post from './post'
import author from './author'
// Then we give our schema to the builder and provide the result to Sanity // Then we give our schema to the builder and provide the result to Sanity
export default createSchema({ export default createSchema({
// We name our schema // We name our schema
...@@ -12,70 +17,7 @@ export default createSchema({ ...@@ -12,70 +17,7 @@ export default createSchema({
// to the ones provided by any plugins that are installed // to the ones provided by any plugins that are installed
types: schemaTypes.concat([ types: schemaTypes.concat([
/* Your types here! */ /* Your types here! */
{ post,
name: 'post', author,
type: 'document',
title: 'Post',
fields: [
{
name: 'title',
title: 'Title',
type: 'string',
},
{
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
},
},
{
name: 'content',
title: 'Content',
type: 'array',
of: [{ type: 'block' }],
},
{
name: 'excerpt',
title: 'Excerpt',
type: 'string',
},
{
name: 'coverImage',
title: 'Cover Image',
type: 'image',
},
{
name: 'date',
title: 'Date',
type: 'datetime',
},
{
name: 'author',
title: 'Author',
type: 'reference',
to: [{ type: 'author' }],
},
],
},
{
name: 'author',
type: 'document',
title: 'Author',
fields: [
{
name: 'name',
title: 'Name',
type: 'string',
},
{
name: 'picture',
title: 'Picture',
type: 'image',
},
],
},
]), ]),
}) })
Files placed here will be served by the Sanity server under the `/static`-prefix
{
// Note: This config is only used to help editors like VS Code understand/resolve
// parts, the actual transpilation is done by babel. Any compiler configuration in
// here will be ignored.
"include": [
"./node_modules/@sanity/base/types/**/*.ts",
"./**/*.ts",
"./**/*.tsx"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment