CoursesAI-powered Sanity developmentRapidly generating placeholder content

AI-powered Sanity development

Lesson
6

Rapidly generating placeholder content

Log in to watch a video walkthrough of this lesson
Log in
Video thumbnail
You may think the only use for AI tools is to write code, but we can use it to write content and run commands to import it.
Log in to mark your progress for each Lesson and Task

Our content model is all defined in code and content can be imported into a Sanity Studio dataset in bulk by creating an NDJSON file. This is the file format which datasets are exported to, where every document in a dataset is represented as JSON on a single line.

Creating scripts to create files like these has previously been a laborious process, especially when it comes to creating richer data structures such as Presenting Portable Text. And this is the sort of complex, busy work that AI excels at and can make simple.

The opinionated rules that you added in the last step contains a section for guidance on creating these sorts of files, with helpful inclusions like including images.

Open a new chat in "Agent" mode and enter something like the following prompt.
I need to create some placeholder content to be able to validate my content model. Looking at all of the content types in the @schemaTypes directory, create an NDJSON file and import it into the production dataset. When running the import, overwrite existing document ID's. Use the guidance from @sanity-opinionated.mdc

You may be prompted to select a dataset when running the import, but once completed, you should now have some posts and other document types in your Sanity Studio.

The prompt above could have been extended to be more creative or ask for a specific number of documents to be created. Try re-running with a few different takes.

Now that all of the content is represented as a single file, you could also write prompts to make edits directly to that file and re-import.

Now we have content, we can render it in a front end.

You have 1 uncompleted task in this lesson
0 of 1