generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
ef298aa
commit 082b30c
Showing
14 changed files
with
730 additions
and
193 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,68 +1,32 @@ | ||
## Obsidian Sample Plugin | ||
## Description | ||
This plugin leverages the great Dataview plugin capabilities to select multiple values returned by a query and include them in your note | ||
|
||
This is a sample plugin for Obsidian (https://obsidian.md). | ||
for example | ||
- select some [[<ingredient>]] from your '#Ingredient' notes as required ingredients for a recipe | ||
- select some of your [[<teamate>]] from your '#Staff' notes as participants for a meeting note | ||
- select some [[<song>]] from your '#Favorite && #Song' notes as songs for a playlist note | ||
and so on... | ||
|
||
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. | ||
Seing all the links related to a query helps selecting them faster and not forgetting some. | ||
|
||
**Note:** The Obsidian API is still in early alpha and is subject to change at any time! | ||
### Demo | ||
TODO | ||
|
||
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. | ||
### Settings | ||
You can Add/Change/Remove as many queries has you want | ||
|
||
### First time developing plugins? | ||
Add a query by hitting "+". | ||
You'll have to set a name, a description and the query. | ||
The query has to be written in the dataviewjs syntax: https://blacksmithgu.github.io/obsidian-dataview/api/intro/ and has to return a dataArray | ||
|
||
Quick starting guide for new plugin devs: | ||
There will be one command per query. Each one is name "Multi Select: {description of the query}" | ||
|
||
- 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. | ||
Once created, you can modify the query by hitting the pencil button or remove it by hitting the garbage button | ||
|
||
### 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. 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 | ||
|
||
- 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/`. | ||
|
||
### Improve code quality with eslint (optional) | ||
- [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. | ||
- To use eslint with this project, make sure to install eslint from terminal: | ||
- `npm install -g eslint` | ||
- To use eslint to analyze this project use this command: | ||
- `eslint main.ts` | ||
- eslint will then create a report with suggestions for code improvement by file and line number. | ||
- 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\` | ||
|
||
|
||
### API Documentation | ||
|
||
See https://github.com/obsidianmd/obsidian-api | ||
### Usage | ||
1. In live preview, position the cursor where you want to include links | ||
2. open the command palette and select the query that you want to execute | ||
3. Select the results that you want to paste at the cursor position | ||
4. You can select an alias where the target note contains aliases in its frontmatter | ||
5. Set append and prepend strings (default prepend string: none, default append string: `", "`) | ||
6. Hit the checkmark button to paste the links in your note: Et voilà! |
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
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
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.12.0", | ||
"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", | ||
"id": "obsidian-multiselect", | ||
"name": "Multi Select", | ||
"version": "0.0.1", | ||
"minAppVersion": "0.13.19", | ||
"description": "Select multiple notes from a dataview query and include their links the current note", | ||
"author": "mdelobelle", | ||
"authorUrl": "https://github.com/mdelobelle", | ||
"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
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,28 @@ | ||
interface Query { | ||
id: string | ||
name: string | ||
description: string | ||
dataviewJSQuery?: string | ||
} | ||
|
||
class Query { | ||
|
||
constructor(name: string = "", | ||
description: string = "", | ||
id: string = "", | ||
dataviewJSQuery: string = null) { | ||
this.name = name | ||
this.description = description | ||
this.id = id | ||
this.dataviewJSQuery = dataviewJSQuery | ||
} | ||
|
||
static copyQuery(target: Query, source: Query) { | ||
target.id = source.id | ||
target.name = source.name | ||
target.description = source.description | ||
target.dataviewJSQuery = source.dataviewJSQuery | ||
} | ||
} | ||
|
||
export default Query |
Oops, something went wrong.