From 2a491efa4ffb84152458a9eb062f93b0543044de Mon Sep 17 00:00:00 2001 From: jaschop <1k5o@tuta.io> Date: Fri, 24 May 2024 22:42:54 +0200 Subject: [PATCH] use file basename and customize header --- extract-todos/extract-todos.qml | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/extract-todos/extract-todos.qml b/extract-todos/extract-todos.qml index 0d548c6..e8e9fd3 100644 --- a/extract-todos/extract-todos.qml +++ b/extract-todos/extract-todos.qml @@ -3,14 +3,22 @@ import QOwnNotesTypes 1.0 Script { property string subFolder; + property string headerText; property variant settingsVariables: [ { - "identifier": "subFolder", - "name": "TODO Subfolder", - "description": "Restrict search for TODOs to this note subfolder.", - "type": "string", - "default": "", - } + "identifier": "subFolder", + "name": "TODO Subfolder", + "description": "Restrict search for TODOs to this note subfolder.", + "type": "string", + "default": "", + }, + { + "identifier": "headerText", + "name": "Header Text", + "description": "Header text for your TODO listing", + "type": "string", + "default": "Open TODOs", + } ]; function init() { @@ -19,13 +27,11 @@ Script { } function extractTodos() { - const path = script.currentNoteFolderPath() + "/" + subFolder; const findResult = script.startSynchronousProcess("find", ["\(", "-name", "*.md", "-or", "-name", "*.txt", "\)", "-printf", "%P\n"], "", path); - const files = findResult.toString().split("\n"); - + const files = findResult.toString().split("\n"); const todoRegex = /^\s*- \[ \]\s*/; - var output = "

Open TODOs

\n"; + var output = "

" + headerText + "

"; for (const i in files) { const file = files[i]; @@ -35,17 +41,22 @@ Script { .filter(s => s.match(todoRegex)) .map(s => s.replace(todoRegex, "")); if (todos.length > 0) { - output += "

" + file + "

"; } } - script.setLabelText("extract todos", output); } + function getBaseName(path) { + const fileName = path.slice(path.lastIndexOf("/") + 1); + const baseName = fileName.slice(0, fileName.indexOf(".")); + return baseName; + } + function onNoteStored(note) { extractTodos() } }