From b1370b772e66cbabcefb23ab10206661d97973e2 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 26 Oct 2023 11:55:17 +0200 Subject: [PATCH] fixed note name being included before frontmatter --- src/main.ts | 15 +++++++++++---- .../.obsidian/plugins/just-share-please/data.json | 2 +- test-vault/Cool Test Note.md | 4 ---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 62a4281..b6de043 100644 --- a/src/main.ts +++ b/src/main.ts @@ -227,15 +227,22 @@ export default class JustSharePleasePlugin extends Plugin { let text = await this.app.vault.cachedRead(file); // strip frontmatter + let frontmatter = /^(---\s*\n.*?\n---)\s*\n(.*)$/s; if (this.settings.stripFrontmatter) - text = text.replace(/^---\s*\n.*?\n---\s*\n(.*)$/s, "$1"); + text = text.replace(frontmatter, "$2"); // strip comments text = text.replace(/%%.*?%%/sg, ""); - // include note name - if (this.settings.includeNoteName) - text = `# ${file.basename}\n\n${text}`; + // include note name (after frontmatter!) + if (this.settings.includeNoteName) { + let title = `# ${file.basename}\n\n`; + if (frontmatter.test(text)) { + text = text.replace(frontmatter, `$1\n\n${title}$2`); + } else { + text = title + text; + } + } // embed attachments directly let attachments = /!\[(.*)]\((.+)\)|!\[\[(.+)]]/g; diff --git a/test-vault/.obsidian/plugins/just-share-please/data.json b/test-vault/.obsidian/plugins/just-share-please/data.json index e17f7f8..4d9592f 100644 --- a/test-vault/.obsidian/plugins/just-share-please/data.json +++ b/test-vault/.obsidian/plugins/just-share-please/data.json @@ -7,7 +7,7 @@ "path": "Cool Test Note.md" } ], - "stripFrontmatter": true, + "stripFrontmatter": false, "includeNoteName": true, "unshareDeletedFiles": false, "autoUpdateShares": false diff --git a/test-vault/Cool Test Note.md b/test-vault/Cool Test Note.md index 1cab006..2118caf 100644 --- a/test-vault/Cool Test Note.md +++ b/test-vault/Cool Test Note.md @@ -1,7 +1,3 @@ ---- -test: yes ---- - This is a cool test note%%with an inline comment%%, my friends! Chemistry!