···11+# vscode
22+.vscode
33+44+# Intellij
55+*.iml
66+.idea
77+88+# npm
99+node_modules
1010+1111+# Don't include the compiled main.js file in the repo.
1212+# They should be uploaded to GitHub releases instead.
1313+main.js
1414+1515+# Exclude sourcemaps
1616+*.map
1717+1818+# obsidian
1919+data.json
2020+2121+# Exclude macOS Finder (System Explorer) View States
2222+.DS_Store
···11+# Obsidian community plugin
22+33+## Project overview
44+55+- Target: Obsidian Community Plugin (TypeScript → bundled JavaScript).
66+- Entry point: `main.ts` compiled to `main.js` and loaded by Obsidian.
77+- Required release artifacts: `main.js`, `manifest.json`, and optional `styles.css`.
88+99+## Environment & tooling
1010+1111+- Node.js: use current LTS (Node 18+ recommended).
1212+- **Package manager: npm** (required for this sample - `package.json` defines npm scripts and dependencies).
1313+- **Bundler: esbuild** (required for this sample - `esbuild.config.mjs` and build scripts depend on it). Alternative bundlers like Rollup or webpack are acceptable for other projects if they bundle all external dependencies into `main.js`.
1414+- Types: `obsidian` type definitions.
1515+1616+**Note**: This sample project has specific technical dependencies on npm and esbuild. If you're creating a plugin from scratch, you can choose different tools, but you'll need to replace the build configuration accordingly.
1717+1818+### Install
1919+2020+```bash
2121+npm install
2222+```
2323+2424+### Dev (watch)
2525+2626+```bash
2727+npm run dev
2828+```
2929+3030+### Production build
3131+3232+```bash
3333+npm run build
3434+```
3535+3636+## Linting
3737+3838+- To use eslint install eslint from terminal: `npm install -g eslint`
3939+- To use eslint to analyze this project use this command: `eslint main.ts`
4040+- eslint will then create a report with suggestions for code improvement by file and line number.
4141+- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder: `eslint ./src/`
4242+4343+## File & folder conventions
4444+4545+- **Organize code into multiple files**: Split functionality across separate modules rather than putting everything in `main.ts`.
4646+- Source lives in `src/`. Keep `main.ts` small and focused on plugin lifecycle (loading, unloading, registering commands).
4747+- **Example file structure**:
4848+ ```
4949+ src/
5050+ main.ts # Plugin entry point, lifecycle management
5151+ settings.ts # Settings interface and defaults
5252+ commands/ # Command implementations
5353+ command1.ts
5454+ command2.ts
5555+ ui/ # UI components, modals, views
5656+ modal.ts
5757+ view.ts
5858+ utils/ # Utility functions, helpers
5959+ helpers.ts
6060+ constants.ts
6161+ types.ts # TypeScript interfaces and types
6262+ ```
6363+- **Do not commit build artifacts**: Never commit `node_modules/`, `main.js`, or other generated files to version control.
6464+- Keep the plugin small. Avoid large dependencies. Prefer browser-compatible packages.
6565+- Generated output should be placed at the plugin root or `dist/` depending on your build setup. Release artifacts must end up at the top level of the plugin folder in the vault (`main.js`, `manifest.json`, `styles.css`).
6666+6767+## Manifest rules (`manifest.json`)
6868+6969+- Must include (non-exhaustive):
7070+ - `id` (plugin ID; for local dev it should match the folder name)
7171+ - `name`
7272+ - `version` (Semantic Versioning `x.y.z`)
7373+ - `minAppVersion`
7474+ - `description`
7575+ - `isDesktopOnly` (boolean)
7676+ - Optional: `author`, `authorUrl`, `fundingUrl` (string or map)
7777+- Never change `id` after release. Treat it as stable API.
7878+- Keep `minAppVersion` accurate when using newer APIs.
7979+- Canonical requirements are coded here: https://github.com/obsidianmd/obsidian-releases/blob/master/.github/workflows/validate-plugin-entry.yml
8080+8181+## Testing
8282+8383+- Manual install for testing: copy `main.js`, `manifest.json`, `styles.css` (if any) to:
8484+ ```
8585+ <Vault>/.obsidian/plugins/<plugin-id>/
8686+ ```
8787+- Reload Obsidian and enable the plugin in **Settings → Community plugins**.
8888+8989+## Commands & settings
9090+9191+- Any user-facing commands should be added via `this.addCommand(...)`.
9292+- If the plugin has configuration, provide a settings tab and sensible defaults.
9393+- Persist settings using `this.loadData()` / `this.saveData()`.
9494+- Use stable command IDs; avoid renaming once released.
9595+9696+## Versioning & releases
9797+9898+- Bump `version` in `manifest.json` (SemVer) and update `versions.json` to map plugin version → minimum app version.
9999+- Create a GitHub release whose tag exactly matches `manifest.json`'s `version`. Do not use a leading `v`.
100100+- Attach `manifest.json`, `main.js`, and `styles.css` (if present) to the release as individual assets.
101101+- After the initial release, follow the process to add/update your plugin in the community catalog as required.
102102+103103+## Security, privacy, and compliance
104104+105105+Follow Obsidian's **Developer Policies** and **Plugin Guidelines**. In particular:
106106+107107+- Default to local/offline operation. Only make network requests when essential to the feature.
108108+- No hidden telemetry. If you collect optional analytics or call third-party services, require explicit opt-in and document clearly in `README.md` and in settings.
109109+- Never execute remote code, fetch and eval scripts, or auto-update plugin code outside of normal releases.
110110+- Minimize scope: read/write only what's necessary inside the vault. Do not access files outside the vault.
111111+- Clearly disclose any external services used, data sent, and risks.
112112+- Respect user privacy. Do not collect vault contents, filenames, or personal information unless absolutely necessary and explicitly consented.
113113+- Avoid deceptive patterns, ads, or spammy notifications.
114114+- Register and clean up all DOM, app, and interval listeners using the provided `register*` helpers so the plugin unloads safely.
115115+116116+## UX & copy guidelines (for UI text, commands, settings)
117117+118118+- Prefer sentence case for headings, buttons, and titles.
119119+- Use clear, action-oriented imperatives in step-by-step copy.
120120+- Use **bold** to indicate literal UI labels. Prefer "select" for interactions.
121121+- Use arrow notation for navigation: **Settings → Community plugins**.
122122+- Keep in-app strings short, consistent, and free of jargon.
123123+124124+## Performance
125125+126126+- Keep startup light. Defer heavy work until needed.
127127+- Avoid long-running tasks during `onload`; use lazy initialization.
128128+- Batch disk access and avoid excessive vault scans.
129129+- Debounce/throttle expensive operations in response to file system events.
130130+131131+## Coding conventions
132132+133133+- TypeScript with `"strict": true` preferred.
134134+- **Keep `main.ts` minimal**: Focus only on plugin lifecycle (onload, onunload, addCommand calls). Delegate all feature logic to separate modules.
135135+- **Split large files**: If any file exceeds ~200-300 lines, consider breaking it into smaller, focused modules.
136136+- **Use clear module boundaries**: Each file should have a single, well-defined responsibility.
137137+- Bundle everything into `main.js` (no unbundled runtime deps).
138138+- Avoid Node/Electron APIs if you want mobile compatibility; set `isDesktopOnly` accordingly.
139139+- Prefer `async/await` over promise chains; handle errors gracefully.
140140+141141+## Mobile
142142+143143+- Where feasible, test on iOS and Android.
144144+- Don't assume desktop-only behavior unless `isDesktopOnly` is `true`.
145145+- Avoid large in-memory structures; be mindful of memory and storage constraints.
146146+147147+## Agent do/don't
148148+149149+**Do**
150150+- Add commands with stable IDs (don't rename once released).
151151+- Provide defaults and validation in settings.
152152+- Write idempotent code paths so reload/unload doesn't leak listeners or intervals.
153153+- Use `this.register*` helpers for everything that needs cleanup.
154154+155155+**Don't**
156156+- Introduce network calls without an obvious user-facing reason and documentation.
157157+- Ship features that require cloud services without clear disclosure and explicit opt-in.
158158+- Store or transmit vault contents unless essential and consented.
159159+160160+## Common tasks
161161+162162+### Organize code across multiple files
163163+164164+**main.ts** (minimal, lifecycle only):
165165+```ts
166166+import { Plugin } from "obsidian";
167167+import { MySettings, DEFAULT_SETTINGS } from "./settings";
168168+import { registerCommands } from "./commands";
169169+170170+export default class MyPlugin extends Plugin {
171171+ settings: MySettings;
172172+173173+ async onload() {
174174+ this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
175175+ registerCommands(this);
176176+ }
177177+}
178178+```
179179+180180+**settings.ts**:
181181+```ts
182182+export interface MySettings {
183183+ enabled: boolean;
184184+ apiKey: string;
185185+}
186186+187187+export const DEFAULT_SETTINGS: MySettings = {
188188+ enabled: true,
189189+ apiKey: "",
190190+};
191191+```
192192+193193+**commands/index.ts**:
194194+```ts
195195+import { Plugin } from "obsidian";
196196+import { doSomething } from "./my-command";
197197+198198+export function registerCommands(plugin: Plugin) {
199199+ plugin.addCommand({
200200+ id: "do-something",
201201+ name: "Do something",
202202+ callback: () => doSomething(plugin),
203203+ });
204204+}
205205+```
206206+207207+### Add a command
208208+209209+```ts
210210+this.addCommand({
211211+ id: "your-command-id",
212212+ name: "Do the thing",
213213+ callback: () => this.doTheThing(),
214214+});
215215+```
216216+217217+### Persist settings
218218+219219+```ts
220220+interface MySettings { enabled: boolean }
221221+const DEFAULT_SETTINGS: MySettings = { enabled: true };
222222+223223+async onload() {
224224+ this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
225225+ await this.saveData(this.settings);
226226+}
227227+```
228228+229229+### Register listeners safely
230230+231231+```ts
232232+this.registerEvent(this.app.workspace.on("file-open", f => { /* ... */ }));
233233+this.registerDomEvent(window, "resize", () => { /* ... */ });
234234+this.registerInterval(window.setInterval(() => { /* ... */ }, 1000));
235235+```
236236+237237+## Troubleshooting
238238+239239+- Plugin doesn't load after build: ensure `main.js` and `manifest.json` are at the top level of the plugin folder under `<Vault>/.obsidian/plugins/<plugin-id>/`.
240240+- Build issues: if `main.js` is missing, run `npm run build` or `npm run dev` to compile your TypeScript source code.
241241+- Commands not appearing: verify `addCommand` runs after `onload` and IDs are unique.
242242+- Settings not persisting: ensure `loadData`/`saveData` are awaited and you re-render the UI after changes.
243243+- Mobile-only issues: confirm you're not using desktop-only APIs; check `isDesktopOnly` and adjust.
244244+245245+## References
246246+247247+- Obsidian sample plugin: https://github.com/obsidianmd/obsidian-sample-plugin
248248+- API documentation: https://docs.obsidian.md
249249+- Developer policies: https://docs.obsidian.md/Developer+policies
250250+- Plugin guidelines: https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines
251251+- Style guide: https://help.obsidian.md/style-guide
+5
LICENSE
···11+Copyright (C) 2020-2025 by Dynalist Inc.
22+33+Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
44+55+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+90
README.md
···11+# Obsidian Sample Plugin
22+33+This is a sample plugin for Obsidian (https://obsidian.md).
44+55+This project uses TypeScript to provide type checking and documentation.
66+The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definition format, which contains TSDoc comments describing what it does.
77+88+This sample plugin demonstrates some of the basic functionality the plugin API can do.
99+- Adds a ribbon icon, which shows a Notice when clicked.
1010+- Adds a command "Open modal (simple)" which opens a Modal.
1111+- Adds a plugin setting tab to the settings page.
1212+- Registers a global click event and output 'click' to the console.
1313+- Registers a global interval which logs 'setInterval' to the console.
1414+1515+## First time developing plugins?
1616+1717+Quick starting guide for new plugin devs:
1818+1919+- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with.
2020+- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
2121+- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
2222+- Install NodeJS, then run `npm i` in the command line under your repo folder.
2323+- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
2424+- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
2525+- Reload Obsidian to load the new version of your plugin.
2626+- Enable plugin in settings window.
2727+- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
2828+2929+## Releasing new releases
3030+3131+- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
3232+- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
3333+- Create 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
3434+- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
3535+- Publish the release.
3636+3737+> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`.
3838+> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
3939+4040+## Adding your plugin to the community plugin list
4141+4242+- Check the [plugin guidelines](https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines).
4343+- Publish an initial version.
4444+- Make sure you have a `README.md` file in the root of your repo.
4545+- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
4646+4747+## How to use
4848+4949+- Clone this repo.
5050+- Make sure your NodeJS is at least v16 (`node --version`).
5151+- `npm i` or `yarn` to install dependencies.
5252+- `npm run dev` to start compilation in watch mode.
5353+5454+## Manually installing the plugin
5555+5656+- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
5757+5858+## Improve code quality with eslint
5959+- [ESLint](https://eslint.org/) 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.
6060+- This project already has eslint preconfigured, you can invoke a check by running`npm run lint`
6161+- Together with a custom eslint [plugin](https://github.com/obsidianmd/eslint-plugin) for Obsidan specific code guidelines.
6262+- A GitHub action is preconfigured to automatically lint every commit on all branches.
6363+6464+## Funding URL
6565+6666+You can include funding URLs where people who use your plugin can financially support it.
6767+6868+The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:
6969+7070+```json
7171+{
7272+ "fundingUrl": "https://buymeacoffee.com"
7373+}
7474+```
7575+7676+If you have multiple URLs, you can also do:
7777+7878+```json
7979+{
8080+ "fundingUrl": {
8181+ "Buy Me a Coffee": "https://buymeacoffee.com",
8282+ "GitHub Sponsor": "https://github.com/sponsors",
8383+ "Patreon": "https://www.patreon.com/"
8484+ }
8585+}
8686+```
8787+8888+## API Documentation
8989+9090+See https://docs.obsidian.md
···11+import {App, Editor, MarkdownView, Modal, Notice, Plugin} from 'obsidian';
22+import {DEFAULT_SETTINGS, MyPluginSettings, SampleSettingTab} from "./settings";
33+44+// Remember to rename these classes and interfaces!
55+66+export default class MyPlugin extends Plugin {
77+ settings: MyPluginSettings;
88+99+ async onload() {
1010+ await this.loadSettings();
1111+1212+ // This creates an icon in the left ribbon.
1313+ this.addRibbonIcon('dice', 'Sample', (evt: MouseEvent) => {
1414+ // Called when the user clicks the icon.
1515+ new Notice('This is a notice!');
1616+ });
1717+1818+ // This adds a status bar item to the bottom of the app. Does not work on mobile apps.
1919+ const statusBarItemEl = this.addStatusBarItem();
2020+ statusBarItemEl.setText('Status bar text');
2121+2222+ // This adds a simple command that can be triggered anywhere
2323+ this.addCommand({
2424+ id: 'open-modal-simple',
2525+ name: 'Open modal (simple)',
2626+ callback: () => {
2727+ new SampleModal(this.app).open();
2828+ }
2929+ });
3030+ // This adds an editor command that can perform some operation on the current editor instance
3131+ this.addCommand({
3232+ id: 'replace-selected',
3333+ name: 'Replace selected content',
3434+ editorCallback: (editor: Editor, view: MarkdownView) => {
3535+ editor.replaceSelection('Sample editor command');
3636+ }
3737+ });
3838+ // This adds a complex command that can check whether the current state of the app allows execution of the command
3939+ this.addCommand({
4040+ id: 'open-modal-complex',
4141+ name: 'Open modal (complex)',
4242+ checkCallback: (checking: boolean) => {
4343+ // Conditions to check
4444+ const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
4545+ if (markdownView) {
4646+ // If checking is true, we're simply "checking" if the command can be run.
4747+ // If checking is false, then we want to actually perform the operation.
4848+ if (!checking) {
4949+ new SampleModal(this.app).open();
5050+ }
5151+5252+ // This command will only show up in Command Palette when the check function returns true
5353+ return true;
5454+ }
5555+ return false;
5656+ }
5757+ });
5858+5959+ // This adds a settings tab so the user can configure various aspects of the plugin
6060+ this.addSettingTab(new SampleSettingTab(this.app, this));
6161+6262+ // If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
6363+ // Using this function will automatically remove the event listener when this plugin is disabled.
6464+ this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
6565+ new Notice("Click");
6666+ });
6767+6868+ // When registering intervals, this function will automatically clear the interval when the plugin is disabled.
6969+ this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
7070+7171+ }
7272+7373+ onunload() {
7474+ }
7575+7676+ async loadSettings() {
7777+ this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial<MyPluginSettings>);
7878+ }
7979+8080+ async saveSettings() {
8181+ await this.saveData(this.settings);
8282+ }
8383+}
8484+8585+class SampleModal extends Modal {
8686+ constructor(app: App) {
8787+ super(app);
8888+ }
8989+9090+ onOpen() {
9191+ let {contentEl} = this;
9292+ contentEl.setText('Woah!');
9393+ }
9494+9595+ onClose() {
9696+ const {contentEl} = this;
9797+ contentEl.empty();
9898+ }
9999+}
···11+/*
22+33+This CSS file will be included with your plugin, and
44+available in the app when your plugin is enabled.
55+66+If your plugin does not need CSS, delete this file.
77+88+*/
···11+import { readFileSync, writeFileSync } from "fs";
22+33+const targetVersion = process.env.npm_package_version;
44+55+// read minAppVersion from manifest.json and bump version to target version
66+const manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
77+const { minAppVersion } = manifest;
88+manifest.version = targetVersion;
99+writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
1010+1111+// update versions.json with target version and minAppVersion from manifest.json
1212+// but only if the target version is not already in versions.json
1313+const versions = JSON.parse(readFileSync('versions.json', 'utf8'));
1414+if (!Object.values(versions).includes(minAppVersion)) {
1515+ versions[targetVersion] = minAppVersion;
1616+ writeFileSync('versions.json', JSON.stringify(versions, null, '\t'));
1717+}