GithubHelp home page GithubHelp logo

drewlyton / sanity-obsidian-plugin Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 118 KB

A plugin for Obsidian that allows you to publish and sync documents from your Obsidian vault to your Sanity Studio.

JavaScript 10.71% TypeScript 88.20% CSS 1.10%
obsidian obsidian-md obsidian-plugin sanity sanity-io sanity-studio

sanity-obsidian-plugin's Introduction

Sanity Publish for Obsidian

Obsidian logo and Sanity logo together

Sanity Publish is a plugin for Obsidian that allows you to publish and sync documents from your Obsidian vault to your Sanity Studio.

⬇️ Installing the plugin

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.

⚙️ Plugin Settings

Sanity API Token

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.

Sanity Project ID

Paste your Sanity project id into this field.

Sanity Dataset Name

Provide the name of the dataset you'd like to publish documents to. This defaults to 'production'.

Sanity Document Type Name

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')

Sanity Title Field

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.

Sanity Body Field

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.

🙌 Hitting Publish

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!

🌄 Uploading Images

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.

🤓 Advanced Settings

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.

🙏 Contributing

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.

sanity-obsidian-plugin's People

Contributors

lishid avatar drewlyton avatar ericaxu avatar edo78 avatar fyears avatar chrisgrieser avatar aidenlx avatar reorx avatar tokuhirom avatar timrogers avatar tfthacker avatar phibr0 avatar taurelas avatar kostapc avatar joethei avatar inouetakuya avatar henrebotha avatar gitmurf avatar clemens-e avatar pozdneev avatar aleksey-rowan avatar

Stargazers

stelko avatar Thomas Drevon avatar  avatar

Watchers

 avatar

sanity-obsidian-plugin's Issues

Add check for sanity_token

When running commands, we should check to ensure the sanity_token and project_id are set and early return with a Notice if not

Speed bumps on install

I'm on macOs 14.4.1, Obsidian v1.5.12.

I was thrilled to come across this plugin, just what I was looking for <3

I followed the instructions of cloning the plugin repo into my ./obsidian/plugins/ folder. The plugin appeared in Obsidian under "Community plugins" as expected, but when I toggled the enable switch, I got this error in the console:

Plugin failure: obsidian-sanity Error: ENOENT: no such file or directory, open '/Users/SOMEPATH/.obsidian/plugins/sanity-obsidian-plugin/main.js'

I solved this by running npm install && npm run build in the sanity-obsidian-plugin folder. Should this happen automatically, executed by Obsidian?

After building, I found the settings UI and added API token etc. Upon testing my first edit (and hitting "Publish"), I got the following error:

Access to XMLHttpRequest at 'https://XYZZY.api.sanity.io/v2023-05-03/data/mutate/production?returnIds=true&returnDocuments=true&visibility=sync' from origin 'app://obsidian.md' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Which is understandable, so I went over to the Sanity project management to add a CORS origin. However, that interface (which, incidentally, I'm partly responsible for creating some years back) will not allow app://obsidian.md as an origin. The only solution then, as far as I can tell, is to use the wildcard * origin (which is less than ideal).

Finally, when I got Obsidian to publish a Sanity document, I realized that the markdown produced by Obsidian is sent to Sanity as type: 'string' not type: 'block'.

So to summarize, the readme could do with some more info

  • npm install && npm run build
  • Remember to add CORS origins in Sanity
  • Heads-up regarding what sort of data types the plugin sends to Sanity

I could whip up a PR for an improved readme? Unless these mishaps I encountered are entirely my fault and could have been avoided in a better way?

Also, it would be super nice if there was an option to convert markdown to block-content/portable-text!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.