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)
This commit is contained in:
Daniel Austin 2024-07-13 17:04:50 +10:00
parent 3842d40077
commit d549bdc32e
3 changed files with 20 additions and 11 deletions

View file

@ -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)

View file

@ -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
}

View file

@ -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}&note=${taskNoteEncoded}`
`omnifocus:///add?name=${taskNameEncoded}&note=${taskNoteEncoded}&due=${taskDate}`
);
}