This package liberates Contentful spaces, creating Sanity projects and schemas as it goes.
npm i -g contentful-to-sanity
Or use it on demand with npx
:
npx contentful-to-sanity@latest --help
1. Open Contentful and navigate to your space: https://app.contentful.com/
- Find your contentful space ID of your project (under Space settings → General)
- Create an API Key and get the Content Delivery API - access token (under Settings → API keys → Content delivery / preview tokens → add api key)
- Create a content management token (under Settings → API keys → Content management tokens → Generate personal token)
2. Setup a clean Sanity v3 Studio and connect it to, or create, the Sanity project and dataset you want as your destination:
npm create sanity@latest --template clean --create-project "Your Project Name" --dataset production --output-path ./migrate
npx contentful-to-sanity@latest -s <space-id> -t <management-token> -a <access-token> ./migrate
cd ./migrate && npx sanity dataset import ./dataset.ndjson
If you chose the clean
template it should look like this
import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
import {schemaTypes} from './schemas'
export default defineConfig({
name: 'default',
title: '<project-name>',
projectId: '<project-id>',
dataset: '<dataset>',
plugins: [deskTool(), visionTool()],
schema: {
types: schemaTypes,
},
})
Now replace the schemaTypes
import with the generated one:
import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {visionTool} from '@sanity/vision'
-import {schemaTypes} from './schemas'
+import {types as schemaTypes} from './schema'
export default defineConfig({
name: 'default',
title: '<project-name>',
npm dev
You don't have to wait for the npx sanity dataset import ./migrate/dataset.ndjson
job to finish before the Studio is ready for use. The Studio will keep up to speed with the progress of the import job in real-time.
For more information on the available commands and their options, run contentful-to-sanity --help
.
MIT © Sanity.io