Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

Edit and publish content

In the previous step, you set up a document type called pet with one field for its name. With your studio running (sanity start) and your browser open on http://localhost:3333, you can now click the pencil button (đź“ť) to create a new pet document.

Editing content

👉 As you can see, the form has just one input field that lets you type text. If you have a pet, feel free to type its name in, or type Fido, Rex, Kokos, or whatever you can come up with. As long as it’s a good name for a pet!

Notice when you’re editing that it activates the synchronization indicator in the bottom left corner of your editor pane. This is the studio syncing your changes in real-time with the hosted Content Lake. In other words, you’re editing content online, even though your studio is running locally. There’s no need to save!

👉 Go to the three-dotted menu in the upper right corner of the document form. Press it and select Inspect. This opens the JSON inspector where you can see how the document data looks something like this:

{
  "_id": "drafts.d2f251cd-3f58-4abb-9b91-287afdd9a49b",
  "_type": "pet",
  "name": "Kokos",
  "_rev": "ky7gn7-579-sbh-pq8-q2qsxepxq",
  "_updatedAt": "2022-02-09T23:02:39.771Z"
}

Recognize the name and _type properties from the last lesson here?

More about the _ properties

You’ll notice that documents made with Sanity often contain properties that start with an underscore (_). These are “system” properties with special properties used by the Studio and backend. _id is unique for all documents and can be specified via the API or created automatically by the backend. An _id can’t be duplicated and is required and can’t be changed.

We have already covered _type, which is required and can’t be changed.

Since Sanity is real-time, we need _rev to keep track of which revision we’re editing. In practice, it’s nothing you’ll ever need to think about it, but it makes it easier for the studio to prevent race conditions, that is, that someone is writing over others’ changes.

The _updatedAt property should be fairly self-explanatory. It updates the timestamp every time there’s a change to the document.

Publishing a document

Notice how the _id value starts with drafts.? This means that the document you’re editing is a draft and not available in the public API, that is, you need to be authenticated to access it.

👉 Press the green Publish button, the studio will make a copy of your document, remove the drafts. part of the _id, and create this document for you in the Content Lake. You will then be able to query it from the web without needing a special token for it.

All changes are recorded and attributed. You can look up a document’s version history by going to the Select version menu, Review changes in the three-dotted menu, or the yellow pencil indicator in the bottom publish bar. The studio will show you what changed and who made the change. It will also allow you to revert to any single change or version.

Document versions and Review Changes

All changes are recorded and attributed. You can loop up a document’s version history by going to the Select version menu, Review changes in the three-dotted menu, or the yellow pencil indicator in the bottom publish bar. The studio will show you what changed and who made the change. It will also allow you to revert to any single change or version.

👉 If you make an edit in the name field again, this will create a new drafts. document. When you’re ready to go live with your changes, you can press Publish. This will overwrite the already published document with your new changes. That’s it!

In the next step, we’ll look at how you can integrate your content into a web-based frontend.

Next: Connect your content →

Was this article helpful?