Skip to content

Commit

Permalink
add newPane parameter to obsidian uri
Browse files Browse the repository at this point in the history
adds an optional `newPane` parameter to target either
a new pane or the existing active pane.  Defaults to 'yes'
  • Loading branch information
pmbauer authored and argenos committed Mar 24, 2021
1 parent 11e47a4 commit 5fd4b01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ The only behaviours I changed were the following:

If a date is not recognized, the link won't be created.

**New in v0.4.0**: It's now possible to use the [Obsidian URI](https://publish.obsidian.md/help/Advanced+topics/Using+obsidian+URI) to open daily notes using natural language by using the nldates action `obsidian://nldates?day=<date here>`. Don't forget to [encode space characters](https://publish.obsidian.md/help/Advanced+topics/Using+obsidian+URI#Encoding) appropriately.
#### [Obsidian URI](https://publish.obsidian.md/help/Advanced+topics/Using+obsidian+URI) **New in v0.4.0**

It's now possible to use the [Obsidian URI](https://publish.obsidian.md/help/Advanced+topics/Using+obsidian+URI) to open daily notes using natural language by using the nldates action `obsidian://nldates?day=<date here>`. Don't forget to [encode space characters](https://publish.obsidian.md/help/Advanced+topics/Using+obsidian+URI#Encoding) appropriately.

| `obsidian://nldates` Parameter | Description |
| --------- | ----------- |
| `day` | natural language date string |
| `newPane` | open note in new pane, default is `yes` |

## Commands and hotkeys

Expand Down
13 changes: 12 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export default class NaturalLanguageDates extends Plugin {
return result;
}

parseTruthy(flag: string): boolean {
return ["y", "yes", "1", "t", "true"].indexOf(flag.toLowerCase()) >= 0;
}

onTrigger(mode: string) {
let activeLeaf: any = this.app.workspace.activeLeaf;
let editor = activeLeaf.view.sourceMode.cmEditor;
Expand Down Expand Up @@ -333,14 +337,21 @@ export default class NaturalLanguageDates extends Plugin {
async actionHandler(params: any) {

let date = this.parseDate(params.day);
let newPane = this.parseTruthy(params.newPane || "yes");

console.log(date);
const {
workspace
} = this.app;

if (date.moment.isValid()) {
let dailyNote = await this.getDailyNote(date.moment);
const leaf = workspace.splitActiveLeaf();

let leaf = workspace.activeLeaf;
if (newPane) {
leaf = workspace.splitActiveLeaf();
}

await leaf.openFile(dailyNote);

workspace.setActiveLeaf(leaf);
Expand Down

0 comments on commit 5fd4b01

Please sign in to comment.