generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
144 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,2 @@ | ||
## 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. | ||
|
||
**Note:** The Obsidian API is still in early alpha and is subject to change at any time! | ||
|
||
This sample plugin demonstrates some of the basic functionality the plugin API can do. | ||
- Changes the default font color to red using `styles.css`. | ||
- Adds a ribbon icon, which shows a Notice when clicked. | ||
- Adds a command "Open Sample Modal" which opens a Modal. | ||
- Adds a plugin setting tab to the settings page. | ||
- Registers a global click event and output 'click' to the console. | ||
- Registers a global interval which logs 'setInterval' to the console. | ||
|
||
### First time developing plugins? | ||
|
||
Quick starting guide for new plugin devs: | ||
|
||
- 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-name` folder. | ||
- Install NodeJS, then run `npm i` in the command line under your repo folder. | ||
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`. | ||
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`. | ||
- Reload Obsidian to load the new version of your plugin. | ||
- Enable plugin in settings window. | ||
- For updates to the Obsidian API run `npm update` in the command line under your repo folder. | ||
|
||
### Releasing new releases | ||
|
||
- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release. | ||
- 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. | ||
- 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 | ||
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. | ||
- Publish the release. | ||
|
||
### Adding your plugin to the community plugin list | ||
|
||
- Publish an initial version. | ||
- Make sure you have a `README.md` file 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. | ||
- `npm i` or `yarn` to install dependencies | ||
- `npm run dev` to start compilation in watch mode. | ||
|
||
### Manually installing the plugin | ||
|
||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. | ||
|
||
### API Documentation | ||
|
||
See https://github.com/obsidianmd/obsidian-api | ||
## QuickAdd | ||
Quickly add new pages or content to your vault. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// babel.config.js | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"clearMocks": true, | ||
"testEnvironment": "node", | ||
"maxConcurrency": 1, | ||
"maxWorkers": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"id": "obsidian-sample-plugin", | ||
"name": "Sample Plugin", | ||
"version": "1.0.1", | ||
"minAppVersion": "0.9.12", | ||
"description": "This is a sample plugin for Obsidian. This plugin demonstrates some of the capabilities of the Obsidian API.", | ||
"author": "Obsidian", | ||
"authorUrl": "https://obsidian.md/about", | ||
"id": "quickadd", | ||
"name": "QuickAdd", | ||
"version": "0.0.0", | ||
"minAppVersion": "0.12.00", | ||
"description": "Quickly add new pages or content to your vault.", | ||
"author": "Christian B. B. Houmann", | ||
"authorUrl": "https://bagerbach.com", | ||
"isDesktopOnly": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
{ | ||
"name": "obsidian-sample-plugin", | ||
"version": "0.12.0", | ||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)", | ||
"name": "quickadd", | ||
"version": "0.0.0", | ||
"description": "Quickly add new pages or content to your vault.", | ||
"main": "main.js", | ||
"scripts": { | ||
"dev": "rollup --config rollup.config.js -w", | ||
"build": "rollup --config rollup.config.js --environment BUILD:production" | ||
"build": "rollup --config rollup.config.js --environment BUILD:production", | ||
"test": "jest" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"author": "Christian B. B. Houmann", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@babel/core": "7.14.3", | ||
"@babel/preset-env": "7.14.2", | ||
"@babel/preset-typescript": "7.13.0", | ||
"@rollup/plugin-commonjs": "^18.0.0", | ||
"@rollup/plugin-node-resolve": "^11.2.1", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/node": "^14.14.37", | ||
"@tsconfig/svelte": "1.0.10", | ||
"@types/jest": "26.0.23", | ||
"@types/node": "14.17.1", | ||
"babel-core": "6.26.3", | ||
"babel-jest": "27.0.1", | ||
"jest": "27.0.1", | ||
"jest-environment-node": "27.0.1", | ||
"obsidian": "^0.12.0", | ||
"rollup": "^2.32.1", | ||
"rollup-plugin-strip-code": "0.2.7", | ||
"rollup-plugin-svelte": "^7.1.0", | ||
"svelte": "^3.37.0", | ||
"svelte-check": "^1.3.0", | ||
"svelte-preprocess": "^4.7.0", | ||
"ts-jest": "27.0.0", | ||
"tslib": "^2.2.0", | ||
"typescript": "^4.2.4" | ||
}, | ||
"dependencies": { | ||
"@popperjs/core": "^2.9.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import typescript from '@rollup/plugin-typescript'; | ||
import {nodeResolve} from '@rollup/plugin-node-resolve'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
|
||
const isProd = (process.env.BUILD === 'production'); | ||
|
||
const banner = | ||
`/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ROLLUP | ||
if you want to view the source visit the plugins github repository | ||
*/ | ||
`; | ||
import svelte from "rollup-plugin-svelte"; | ||
import autoPreprocess from "svelte-preprocess"; | ||
import stripCode from "rollup-plugin-strip-code"; | ||
|
||
export default { | ||
input: 'main.ts', | ||
input: 'src/main.ts', | ||
output: { | ||
dir: '.', | ||
sourcemap: 'inline', | ||
sourcemapExcludeSources: isProd, | ||
format: 'cjs', | ||
exports: 'default', | ||
banner, | ||
}, | ||
external: ['obsidian'], | ||
plugins: [ | ||
typescript(), | ||
nodeResolve({browser: true}), | ||
commonjs(), | ||
nodeResolve({ browser: true, dedupe: ["svelte"] }), | ||
commonjs({ include: "node_modules/**" }), | ||
svelte({ | ||
emitCss: false, | ||
preprocess: autoPreprocess(), | ||
}), | ||
process.env["BUILD"] ? stripCode({ | ||
start_comment: 'START.DEVCMD', | ||
end_comment: 'END.DEVCMD' | ||
}) : null | ||
] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {Plugin} from 'obsidian'; | ||
import {DEFAULT_SETTINGS, QuickAddSettingsTab} from "./quickAddSettingsTab"; | ||
|
||
|
||
export default class QuickAdd extends Plugin { | ||
settings: QuickAddSettingsTab; | ||
|
||
async onload() { | ||
console.log('Loading QuickAdd'); | ||
|
||
await this.loadSettings(); | ||
|
||
this.addCommand({ | ||
id: 'runQuickAdd', | ||
name: 'Run QuickAdd', | ||
callback: () => { | ||
|
||
} | ||
}) | ||
|
||
/*START.DEVCMD*/ | ||
this.addCommand({ | ||
id: 'reloadQuickAdd', | ||
name: 'Reload QuickAdd (dev)', | ||
callback: () => { // @ts-ignore - for this.app.plugins | ||
const id: string = this.manifest.id, plugins = this.app.plugins; | ||
plugins.disablePlugin(id).then(() => plugins.enablePlugin(id)); | ||
}, | ||
}); | ||
/*END.DEVCMD*/ | ||
|
||
this.addSettingTab(new QuickAddSettingsTab(this.app, this)); | ||
} | ||
|
||
onunload() { | ||
console.log('Unloading QuickAdd'); | ||
} | ||
|
||
async loadSettings() { | ||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); | ||
} | ||
|
||
async saveSettings() { | ||
await this.saveData(this.settings); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {App, PluginSettingTab, Setting} from "obsidian"; | ||
import type QuickAdd from "./main"; | ||
|
||
export interface QuickAddSettings { | ||
|
||
} | ||
|
||
export const DEFAULT_SETTINGS: QuickAddSettings = { | ||
} | ||
|
||
export class QuickAddSettingsTab extends PluginSettingTab { | ||
plugin: QuickAdd; | ||
|
||
constructor(app: App, plugin: QuickAdd) { | ||
super(app, plugin); | ||
this.plugin = plugin; | ||
} | ||
|
||
display(): void { | ||
let {containerEl} = this; | ||
containerEl.empty(); | ||
|
||
containerEl.createEl('h2', {text: 'QuickAdd Settings'}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +0,0 @@ | ||
/* Sets all the text color to red! */ | ||
body { | ||
color: red; | ||
} | ||
Oops, something went wrong.