Content mapping in Sanity Create
Bridge the gap between Create and Studio with content mapping
Sanity Create is a great tool for freestyle writing, but when it's time to put your creative output to work, you'll probably want to move everything into a structured environment where it can enjoy all of the manifold benefits of treating content as data—Sanity Studio!
- From Sanity Create, check if content mapping has been enabled. Move your cursor around a bit so you can see the top menu and the Notes button in the top left corner. If you can see another button in the top right corner labeled Studio Link or, on smaller screens, with an icon resembling three boxes arranged in a diagram (a schema!), you should be good to proceed.
- Click the Studio Link button to reveal the aptly titled Studio Link panel:
- Find your project in the Select project menu. If not automatically selected for you, find your studio deployment and workspace in the appropriate dropdowns. Then, find the document type you want to map your content to.
- With your document type selected, click the button labeled Start adding content -> to proceed.
- The link panel will change to show a "minimap" of the selected content type, with its fields laid out in a tree structure. Fields with a little arrow on their left can be clicked to expand and reveal their values.
Note also the bottom right status indicator, which shows the background mapping agent already making progress. It will keep working in the background, intelligently mapping your content to corresponding fields.
As your content is mapped, you'll see the minimap tree of document fields starting to fill out with content. You might also notice the colors changing as the mapping agent finishes with a field.
- Green – Automatically mapped
- Gray – No mapping found
- Yellow – Manually mapped
- Black / white – Not yet analyzed
Fields that the bot has successfully mapped turn green, while fields with no mapping found are gray.
The yellow-colored field in the screenshot above indicates a field where an editor has actively overruled the suggested mapping and manually linked a bit of content to a field, while text in black or white (depending on whether or not the dark mode is active) indicates content that the mapping agent hasn't yet analyzed.
While the automatic mapping is quite good (really!), you may at times want to manually adjust how your content in Create matches up with your studio schema. The tools you need to make these changes are at your finger tips.
- To map a content block, like a paragraph or an image, to a specific field, click on the item to reveal its context menu, and find the option to Map to field... as shown below.
- Selecting Map to field... will cause the interface to direct focus to the link panel, where you can select an appropriate field to map your selected content to. In the example below, we mapped the first image in the document to the Cover Image > Asset field. User-defined mappings are shown in yellow, instead of green for auto-mapped or gray for unmapped fields.
- Similarly, if any content is mapped incorrectly, you can unmap it by clicking the Clear mapping button. That particular chunk of content will stay unmapped until you decide to assign it otherwise.
- For more granular control, you can select specific sentences or phrases and map them individually to Studio fields.
- As also demonstrated in the previous screenshot, leaving some contextual hints for the mapping agent can be quite effective. You can read more about this in the section on [content mapping tips and tricks](LINK)
With these tools, you can control exactly how your content in Sanity Create will be translated into structured data in Sanity Studio. All that is left to do is to actually create that new document with all your content already mapped.
Once you're happy with your mappings, find the fairly conspicuous button labeled + Link to a new document in the link panel.
Clicking it should result in a visual confirmation of success, and the button label changing to Open linked document. Click it to open the connected studio with your new document selected.
You'll notice that your new document in the studio is in a read-only state while linked to its counterpart in Create.
Any further changes you make in Create will be synced with the studio document automatically, so you can continue refining and expanding your content without worrying about manually transferring anything.
As mentioned, your document will appear as read-only in your studio while linked to Create. When the time comes, click the Unlink button in the bottom right corner to sever the connection and edit your document in the studio.
Clicking Unlink will cause a dialog to appear, informing you of the consequences. Confirm to dismiss it and unlock the document for editing in the studio.
Protip
// callout: PROTIP: Unlinking does not delete anything! You can keep on editing your document in Sanity Create, though the changes will no longer sync to the studio version. They are no longer connected.
- Procedural discovery. The mapping agent works procedurally on one bit of content at a time, but it can make several passes, so it might re-visit and re-evaluate mappings as it moves through your content. You can use this to your advantage by adding content hints above content blocks to quickly make the agent reconsider its choices.
In the example above, the image was originally judged to be part of the blog post body
field, but remapped to the coverImage
field after some gentle nudging.
- Mark words, lines, or whole blocks as Context to make the mapping agent treat your notes as notes that should not be mapped to any field. Use partial mapping to give the agent the value of a field explicitly in a single-line format:
// [fieldName]: [value]
- what
- can
- go
- wrong
Content mapping is a powerful feature that bridges the gap between the freeform writing environment of Sanity Create and the structured content model of Sanity Studio. It allows you to seamlessly transfer your creative work from Create into a well-defined schema in Studio, making it easy to leverage the benefits of structured content without sacrificing the flexibility and ease of use that Create provides.