Skip to content

Commit

Permalink
use file basename and customize header
Browse files Browse the repository at this point in the history
  • Loading branch information
jaschop-1k5o committed May 24, 2024
1 parent 481a4bc commit 2a491ef
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions extract-todos/extract-todos.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 = "<h1>Open TODOs</h1>\n";
var output = "<h1>" + headerText + "</h1>";

for (const i in files) {
const file = files[i];
Expand All @@ -35,17 +41,22 @@ Script {
.filter(s => s.match(todoRegex))
.map(s => s.replace(todoRegex, ""));
if (todos.length > 0) {
output += "<h3>" + file + "</h3><ul>\n";
output += "<h3>" + getBaseName(file) + "</h3><ul>";
for (const j in todos) {
output += "<p>" + todos[j] + "</p>\n";
output += "<p>" + todos[j] + "</p>";
}
output += "</ul>\n";
output += "</ul>";
}
}

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() }
}

0 comments on commit 2a491ef

Please sign in to comment.