Sanity Publish is a plugin for Obsidian that allows you to publish and sync documents from your Obsidian vault to your Sanity Studio.
Sanity Publish is in alpha and not currently available through the Community Plugins marketplace. So, in order to install it into your Obsidian vault, you'll have to clone the repository manually. You can do that by running the following command from your vault's root directory:
cd .obsidian/plugins && git clone https://github.com/drewlyton/sanity-obsidian-plugin.git
Once the repo is cloned into your plugins
folder, restart Obsidian and navigate to 'Settings'. You should see 'Sanity Publish' in your list of Installed Plugins. Enable the plugin and then navigate to the plugin settings to continue configuration.
In order for Obsidian to sync data with your Sanity studio, you must provide an API token for your Sanity project with read/write access. You can find a guide for how to generate Sanity access tokens here.
Note: by providing this API token, you are granting 'Sanity Publish' and any other installed Obsidian plugin the ability to publish to your Studio on your behalf. Tread lightly here and ensure that you trust the authors of all plugins in your vault before doing this.
Paste your Sanity project id into this field.
Provide the name of the dataset you'd like to publish documents to. This defaults to 'production'.
Provide the name of document type in your Sanity project's schema that you'd like to publish documents to (i.e. 'post' or 'blog')
Provide the field name that represents a title
in your project's schema. Sanity Publish will sync the file name in Obsidian with this field. If you don't want to sync the file name, you can leave this blank.
Provide the field name that matches the body of your file's content. Sanity Publish will sync the Obsidian document's contents with this field in your studio.
Once you've configured the plugin settings, you can navigate to a document you'd like to publish, open the command pallete, and search for Sanity Publish
.
Hitting enter will create or update a draft document in your Sanity Studio. It will also update the frontmatter of your file in Obsidian to store the sanity_id
. This allows you to update the document after it's initially published.
Note that changing or removing this sanity_id
may have unintended consequences. However, it can also be very useful to update this ID field once you've published your document in the Studio. This allows you to update the title and body of your published document right from Obsidian!
One convenient additional feature of Sanity Publish is the ability to upload images to Sanity from Obsidian. By right clicking on an embedded image in your Obsidian document, you can click the Upload to Sanity
menu action and automatically have your image uploaded and the content of your document changed to link to the Sanity CDN.
When you publish a document, we automatically run this process on all embedded images.
If you're like me, while working on an article I often keep previous drafts and cut content below a comment in the document. Something along the lines of:
Content I want to publish
<!-- DRAFTS -->
Content I don't want to publish
Sanity Publish allows you to set a "Content Divider" string for this reason. Just paste your usual divider comment text and when you go to publish, the only content that will be published to Sanity will be that which is above that dividing line.
Sanity Publish is currently mostly a personal pet project for my own publishing workflow. However, if you find it useful and come across any bugs or feature ideas while using it, please make a new issue here on GitHub.