From d549bdc32e538c232f2e2305b27c4696b3f0c636 Mon Sep 17 00:00:00 2001 From: Daniel Austin Date: Sat, 13 Jul 2024 17:04:50 +1000 Subject: [PATCH] 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}` ); }