Obsidian Sample Plugin
This is a sample plugin for Obsidian (https://obsidian.md).
This project uses TypeScript to provide type checking and documentation. The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definition format, which contains TSDoc comments describing what it does.
This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open modal (simple)" which opens a Modal.
- Adds a plugin setting tab to the settings page.
- Registers a global click event and outputs a Notice on click.
- Registers a global interval which logs 'setInterval' to the console.
First time developing plugins?
Quick starting guide for new plugin devs:
- Check if someone already developed a plugin for what you want! There might be an existing plugin similar enough that you can partner up with.
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
- Clone your repo to a local development folder. For convenience, you can place this folder in your
.obsidian/plugins/your-plugin-namefolder. - Install NodeJS, then run
npm iin the command line under your repo folder. - Run
npm run devto compile your plugin fromsrc/main.tstomain.js. - Make changes to
src/main.ts(or create new.tsfiles). Those changes should be automatically compiled intomain.js. - Reload Obsidian to load the new version of your plugin.
- Enable plugin in settings window.
- For updates to the Obsidian API run
npm updatein the command line under your repo folder.
Releasing new releases
This template includes a GitHub Actions workflow, .github/workflows/release.yml, that builds your plugin and drafts a release whenever you push a tag.
- If your new release needs a newer version of Obsidian, update
minAppVersioninmanifest.jsonfirst. - Run
npm version patch,npm version minorornpm version major. This bumps the version inpackage.jsonandmanifest.json, and adds the new version toversions.jsonso older versions of Obsidian can download a compatible older version of your plugin. npm versionalso commits these changes and tags the commit with the new version, such as1.0.1, so you don't need to create the tag yourself. The tag has novprefix, because.npmrcsetstag-version-prefix="".- Push the commit and the tag, for example
git pushand thengit push origin 1.0.1. - The workflow then builds
main.js, creates a build provenance attestation formain.jsandstyles.css(if present), and creates a draft GitHub release withmanifest.json,main.jsandstyles.cssattached. - Open the draft on your repo's Releases page, add release notes, and publish it.
Users can check that a release file was built by your workflow from your repository with gh attestation verify main.js --repo <owner>/<repo>. Artifact attestations are available for public repositories.
If you do not use GitHub Actions, you can release by hand instead:
- Update the version in
manifest.jsonand add it toversions.json(or runnpm versionas above). - Run
npm run build. - Create a new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix
v. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases - Upload the files
manifest.json,main.js,styles.cssas binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release. - Publish the release.
Adding your plugin to the community plugin list
- Check the plugin guidelines.
- Publish an initial version.
- Make sure you have a
README.mdfile in the root of your repo. - Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
How to use
- Clone this repo.
- Make sure your NodeJS is at least v18 (
node --version). npm ito install dependencies.npm run devto start compilation in watch mode.
Manually installing the plugin
- Copy over
main.js,styles.css,manifest.jsonto your vaultVaultFolder/.obsidian/plugins/your-plugin-id/.
Improve code quality with eslint
- ESLint is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- This project already has eslint preconfigured, you can invoke a check by running
npm run lint - Together with a custom eslint plugin for Obsidan specific code guidelines.
- A GitHub action is preconfigured to automatically lint every commit on all branches.
Document your code with TSDoc
- The sample code documents its classes, functions and settings with TSDoc comments (
/** ... */). - Your editor shows these comments when you hover over a name or pick it from autocomplete, the same way it shows the documentation in
obsidian.d.ts. - You can document your own code the same way if you like. It is optional, and most helpful where a name alone does not explain what something does.
Funding URL
You can include funding URLs where people who use your plugin can financially support it.
The simple way is to set the fundingUrl field to your link in your manifest.json file:
{
"fundingUrl": "https://buymeacoffee.com"
}
If you have multiple URLs, you can also do:
{
"fundingUrl": {
"Buy Me a Coffee": "https://buymeacoffee.com",
"GitHub Sponsor": "https://github.com/sponsors",
"Patreon": "https://www.patreon.com/"
}
}
API Documentation
Contributing to this sample plugin
Only collaborators can open pull requests in this repository. To propose a change:
- Fork the repository and commit the change on a branch in your fork.
- Open an issue that explains the change and why it is needed, and links your branch or commit.
- A maintainer reviews the proposal and, if it is accepted, lands the change.
If you created your plugin from this template, remove this section from your README.