From 54828d1159d6c04d64b31149217a3a46f4e42db4 Mon Sep 17 00:00:00 2001 From: Matias Forbord Date: Sat, 12 Mar 2022 18:30:49 +0800 Subject: [PATCH] experimental folder exclusion --- model/TodoParser.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/model/TodoParser.ts b/model/TodoParser.ts index 74ff949..8499ddd 100644 --- a/model/TodoParser.ts +++ b/model/TodoParser.ts @@ -3,19 +3,28 @@ import { TodoItem, TodoItemStatus } from '../model/TodoItem'; import { DateTime } from 'luxon'; import { extractDueDateFromDailyNotesFile } from '../util/DailyNoteParser'; +const pattern = /(-|\*) \[(\s|x)?\]\s(.*)/g; + +const excludedFolders: string[] = []; // TODO: Read from settings +const excludeFolder = (folder: string): boolean => + excludedFolders.filter(excludedFolder => folder.startsWith(excludedFolder)).length > 0; + export class TodoParser { private dateParser: DateParser; - constructor(dateParser: DateParser) { + constructor (dateParser: DateParser) { this.dateParser = dateParser; } - async parseTasks(filePath: string, fileContents: string): Promise { - const pattern = /(-|\*) \[(\s|x)?\]\s(.*)/g; - return [...fileContents.matchAll(pattern)].map((task) => this.parseTask(filePath, task)); + async parseTasks (filePath: string, fileContents: string): Promise { + if (excludeFolder(filePath)) { + return []; + } + + return [...fileContents.matchAll(pattern)].map(task => this.parseTask(filePath, task)); } - private parseTask(filePath: string, entry: RegExpMatchArray): TodoItem { + private parseTask (filePath: string, entry: RegExpMatchArray): TodoItem { const todoItemOffset = 2; // Strip off `-|* ` const status = entry[2] === 'x' ? TodoItemStatus.Done : TodoItemStatus.Todo; const description = entry[3]; @@ -36,7 +45,7 @@ export class TodoParser { ); } - private parseDueDate(description: string, filePath: string): DateTime | undefined { + private parseDueDate (description: string, filePath: string): DateTime | undefined { const taggedDueDate = this.dateParser.parseDate(description); if (taggedDueDate) { return taggedDueDate;