From 177af7f8beee2b8ada498168fa7d4d8b929081f3 Mon Sep 17 00:00:00 2001 From: Sam Morrison Date: Tue, 2 Apr 2024 11:23:36 -0400 Subject: [PATCH 1/8] replace spaces in titles with %20F --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 803e056..0b4c631 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,7 +55,7 @@ export default class TasksToOmnifocus extends Plugin { let taskName = task.replace("- [ ] ", ""); let taskNameEncoded = encodeURIComponent(taskName); let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F"); - let vaultName = app.vault.getName(); + let vaultName = app.vault.getName().replace(/\s/g, "%20"); let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL); window.open( From fe0ec58056983e1abcef36492f94227f2a54fca5 Mon Sep 17 00:00:00 2001 From: Sam Morrison Date: Tue, 2 Apr 2024 11:25:38 -0400 Subject: [PATCH 2/8] fix typing of boolean arg --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 0b4c631..fd8f421 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,7 +41,7 @@ export default class TasksToOmnifocus extends Plugin { this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this)); } - async addToOmnifocus(isSelection: bool, editor: Editor, view: MarkdownView) { + async addToOmnifocus(isSelection: boolean, editor: Editor, view: MarkdownView) { var editorText; if (isSelection) { editorText = editor.getSelection(); From 69bd5fb946608229d147f6b8a9069a1bdb4fdbb2 Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 16:22:23 +1000 Subject: [PATCH 3/8] chore: Address TS warnings --- src/main.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main.ts b/src/main.ts index fd8f421..41c782d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,6 @@ -import { serialize } from "monkey-around"; import { MarkdownView, - CachedMetadata, - Notice, Plugin, - TFile, - Vault, Editor, } from "obsidian"; @@ -42,21 +37,21 @@ export default class TasksToOmnifocus extends Plugin { } async addToOmnifocus(isSelection: boolean, editor: Editor, view: MarkdownView) { - var editorText; + let editorText; if (isSelection) { editorText = editor.getSelection(); } else { editorText = editor.getValue(); } try { - let tasks = editorText.match(/- \[ \] .*/g); + const tasks = editorText.match(/- \[ \] .*/g); - for (let task of tasks) { - let taskName = task.replace("- [ ] ", ""); - let taskNameEncoded = encodeURIComponent(taskName); - let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F"); - let vaultName = app.vault.getName().replace(/\s/g, "%20"); - let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL); + for (const task of tasks) { + const taskName = task.replace("- [ ] ", ""); + const taskNameEncoded = encodeURIComponent(taskName); + const noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F"); + const vaultName = app.vault.getName().replace(/\s/g, "%20"); + const taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL); window.open( `omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}` @@ -64,7 +59,7 @@ export default class TasksToOmnifocus extends Plugin { } if (this.settings.markComplete) { - let completedText = editorText.replace(/- \[ \]/g, "- [x]"); + const completedText = editorText.replace(/- \[ \]/g, "- [x]"); if (isSelection) { editor.replaceSelection(completedText); } else { @@ -73,7 +68,7 @@ export default class TasksToOmnifocus extends Plugin { } } catch (err) { - + console.error('Error extracting tasks', err); } } From d7759d85529f34a9679e837c6393b6bbf000baa6 Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 16:33:58 +1000 Subject: [PATCH 4/8] fix: Allow dash and asterisk marked tasks (#6) Fix for issue #6 -- allows both "- [ ]" and "* [ ]" as task indicators. --- src/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 41c782d..4444f35 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,10 +44,10 @@ export default class TasksToOmnifocus extends Plugin { editorText = editor.getValue(); } try { - const tasks = editorText.match(/- \[ \] .*/g); + const tasks = editorText.match(/[-*] \[ \] .*/g); for (const task of tasks) { - const taskName = task.replace("- [ ] ", ""); + const taskName = task.replace(/[-*] \[ \] /, ""); const taskNameEncoded = encodeURIComponent(taskName); const noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F"); const vaultName = app.vault.getName().replace(/\s/g, "%20"); @@ -59,7 +59,7 @@ export default class TasksToOmnifocus extends Plugin { } if (this.settings.markComplete) { - const completedText = editorText.replace(/- \[ \]/g, "- [x]"); + const completedText = editorText.replace(/([-*]) \[ \]/g, "$1 [x]"); if (isSelection) { editor.replaceSelection(completedText); } else { From 3842d4007707e468d33c546e9bfc23e329fc0c7a Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 16:44:11 +1000 Subject: [PATCH 5/8] build: Add release workflow and CHANGES --- .github/workflows/release.yml | 34 ++++++++++++++++++++++++++++++++++ CHANGES.md | 4 ++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 CHANGES.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a83cd66 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release Obsidian plugin + +on: + push: + tags: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + + - name: Build plugin + run: | + npm install + npm run build + + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + tag="${GITHUB_REF#refs/tags/}" + + gh release create "$tag" \ + --title="$tag" \ + --draft \ + main.js manifest.json \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..28ff2b0 --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,4 @@ +## 1.1.0 + +- Fixes issue with vault names containing spaces (#4) (shabegom) +- Accepts "* [ ]" in addition to "- [ ]" as task indicates (#6) From d549bdc32e538c232f2e2305b27c4696b3f0c636 Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 17:04:50 +1000 Subject: [PATCH 6/8] feat: Allow due date to be set (#11) Fix for issue #11, you can set a due date in YYYY-MM-DD format using "//" (similar to Confluence Markdown) --- CHANGES.md | 1 + manifest.json | 18 +++++++++--------- src/main.ts | 12 ++++++++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 28ff2b0..f1450a1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,3 +2,4 @@ - Fixes issue with vault names containing spaces (#4) (shabegom) - Accepts "* [ ]" in addition to "- [ ]" as task indicates (#6) +- Set a due date by adding "// YYYY-MM-DD" to end of task (#11) diff --git a/manifest.json b/manifest.json index 2107904..f2b7b8b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,11 +1,11 @@ { - "id": "tasks-to-omnifocus", - "name": "Send Tasks to OmniFocus", - "version": "1.0.7", - "minAppVersion": "0.12.0", - "description": "An Obsidian plugin will extract tasks from the current note and create them in OmniFocus.", - "author": "Henry Gustafson", - "authorUrl": "https://lizard-heart.github.io", - "fundingUrl": "https://buymeacoffee.com/lizardheart", - "isDesktopOnly": false + "id": "tasks-to-omnifocus", + "name": "Send Tasks to OmniFocus", + "version": "1.1.0", + "minAppVersion": "0.12.0", + "description": "An Obsidian plugin will extract tasks from the current note and create them in OmniFocus.", + "author": "Henry Gustafson", + "authorUrl": "https://lizard-heart.github.io", + "fundingUrl": "https://buymeacoffee.com/lizardheart", + "isDesktopOnly": false } diff --git a/src/main.ts b/src/main.ts index 4444f35..7d0f676 100644 --- a/src/main.ts +++ b/src/main.ts @@ -47,14 +47,22 @@ export default class TasksToOmnifocus extends Plugin { const tasks = editorText.match(/[-*] \[ \] .*/g); for (const task of tasks) { - const taskName = task.replace(/[-*] \[ \] /, ""); + let taskName = task.replace(/[-*] \[ \] /, ""); + // check if taskName has "//" followed by a date, and if so extract the date for later use and remove it from taskName + const dateMatch = taskName.match(/(\/\/\s*)(\d{4}-\d{2}-\d{2})/); + let taskDate = ""; + if (dateMatch) { + taskDate = dateMatch[2]; + taskName = taskName.replace(dateMatch[0], ""); + console.log(`Setting taskDate to ${taskDate}`); + } const taskNameEncoded = encodeURIComponent(taskName); const noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F"); const vaultName = app.vault.getName().replace(/\s/g, "%20"); const taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL); window.open( - `omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}` + `omnifocus:///add?name=${taskNameEncoded}¬e=${taskNoteEncoded}&due=${taskDate}` ); } From 7d8784f6c4ac4e1d95e6ec08fbf5c8a9479d7ba1 Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 18:48:50 +1000 Subject: [PATCH 7/8] docs: Updating doc files --- CHANGES.md | 18 +++++++++++++++--- README.md | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f1450a1..e5caa8e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,17 @@ -## 1.1.0 +## 1.1.0 (July 2024) -- Fixes issue with vault names containing spaces (#4) (shabegom) -- Accepts "* [ ]" in addition to "- [ ]" as task indicates (#6) +- Fixes issue with vault names containing spaces (#4). Thanks to shabegom. +- Accepts "* [ ]" in addition to "- [ ]" as task indicators (#6) - Set a due date by adding "// YYYY-MM-DD" to end of task (#11) + +## 1.0.7 (June 2023) + +- Fixed issue with duplicate tasks. + +## 1.0.6 (March 2023) + +- Adds a command to export selection to Omnifocus. Thanks to mattsmallman. + +## 1.0.4 - 1.0.5 (Feb-Mar 2023) + +- Initial releases. diff --git a/README.md b/README.md index 84c5b96..e8d4590 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,15 @@ This plugin will extract tasks from the current note open in Obsidian and create 4. Asign any projects and tasks in the Omnifocus modal that appears 5. The tasks should be marked as complete in Obsidian if that setting is enabled +## Examples + +```markdown +- [ ] This task will be sent to OmniFocus +- [x] This task will not (already checked) +* [ ] This task will be sent to OmniFocus +- [ ] This task is due 1 Feb // 2025-02-01 +``` + ## Support In case you want to support development:
From 66b83fb68f73887521e4beaf14fda9590a4597bc Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 20:22:23 +1000 Subject: [PATCH 8/8] fix: Remove console log Also avoid `app` directly, prefer `this.app`. Guidelines: https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines --- src/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7d0f676..b62806d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,11 +54,10 @@ export default class TasksToOmnifocus extends Plugin { if (dateMatch) { taskDate = dateMatch[2]; taskName = taskName.replace(dateMatch[0], ""); - console.log(`Setting taskDate to ${taskDate}`); } const taskNameEncoded = encodeURIComponent(taskName); const noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F"); - const vaultName = app.vault.getName().replace(/\s/g, "%20"); + const vaultName = this.app.vault.getName().replace(/\s/g, "%20"); const taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL); window.open(