Skip to content

Commit

Permalink
Merge pull request #12 from chhoumann/v1.5.1
Browse files Browse the repository at this point in the history
chhoumann authored May 23, 2021

Verified

This commit was signed with the committer’s verified signature.
scolladon Sebastien
2 parents c36de61 + 56de66d commit 696356f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/metaController.ts
Original file line number Diff line number Diff line change
@@ -302,9 +302,7 @@ 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}`);

if (line.match(regexp)) {
if (this.lineMatch(property, line)) {
return this.updatePropertyLine(property, newValue);
}

@@ -314,6 +312,13 @@ export default class MetaController {
await this.app.vault.modify(file, newFileContent);
}

private lineMatch(property: Partial<Property>, 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<Property>, newValue: string) {
let newLine: string;

@@ -349,9 +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}`);
fileContent = fileContent.map(line => {
if (line.match(regexp)) {

if (this.lineMatch(prop, line)) {
return this.updatePropertyLine(prop, prop.content)
}

0 comments on commit 696356f

Please sign in to comment.