From 56866951dce84d817367798ffdec1d4404eb7a91 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sun, 23 May 2021 17:02:20 +0200 Subject: [PATCH 1/2] Hotfix: fixed bug that was accidently reintroduced --- src/metaController.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/metaController.ts b/src/metaController.ts index 171289d..cd73cc3 100644 --- a/src/metaController.ts +++ b/src/metaController.ts @@ -302,9 +302,10 @@ export default class MetaController { const fileContent = await this.app.vault.read(file); const newFileContent = fileContent.split("\n").map(line => { - const regexp = new RegExp(`^\s*${property.key}`); + const propertyRegex = new RegExp(`^\s*${property.key}:`); + const tagRegex = new RegExp(`^\s*#${property.key}`); - if (line.match(regexp)) { + if (line.match(propertyRegex) || line.match(tagRegex)) { return this.updatePropertyLine(property, newValue); } @@ -350,8 +351,11 @@ export default class MetaController { for (const prop of properties) { const regexp = new RegExp(`^\s*${prop.key}`); + const tagRegex = new RegExp(`^\s*#${prop.key}`); + fileContent = fileContent.map(line => { - if (line.match(regexp)) { + + if (line.match(regexp) || line.match(tagRegex)) { return this.updatePropertyLine(prop, prop.content) } From 56de66d87b2fd3efe4ccea4e2c95f8066dd80492 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sun, 23 May 2021 17:06:20 +0200 Subject: [PATCH 2/2] Refactor --- src/metaController.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/metaController.ts b/src/metaController.ts index cd73cc3..9199700 100644 --- a/src/metaController.ts +++ b/src/metaController.ts @@ -302,10 +302,7 @@ export default class MetaController { const fileContent = await this.app.vault.read(file); const newFileContent = fileContent.split("\n").map(line => { - const propertyRegex = new RegExp(`^\s*${property.key}:`); - const tagRegex = new RegExp(`^\s*#${property.key}`); - - if (line.match(propertyRegex) || line.match(tagRegex)) { + if (this.lineMatch(property, line)) { return this.updatePropertyLine(property, newValue); } @@ -315,6 +312,13 @@ export default class MetaController { await this.app.vault.modify(file, newFileContent); } + private lineMatch(property: Partial, line: string) { + const propertyRegex = new RegExp(`^\s*${property.key}:`); + const tagRegex = new RegExp(`^\s*#${property.key}`); + + return line.match(propertyRegex) || line.match(tagRegex); + } + private updatePropertyLine(property: Partial, newValue: string) { let newLine: string; @@ -350,12 +354,9 @@ export default class MetaController { let fileContent = (await this.app.vault.read(file)).split("\n"); for (const prop of properties) { - const regexp = new RegExp(`^\s*${prop.key}`); - const tagRegex = new RegExp(`^\s*#${prop.key}`); - fileContent = fileContent.map(line => { - if (line.match(regexp) || line.match(tagRegex)) { + if (this.lineMatch(prop, line)) { return this.updatePropertyLine(prop, prop.content) }