fix: add regex to find front matter

This commit is contained in:
Kelvin John Falk Szolnoky 2024-01-22 22:38:04 +01:00
parent 40cde2b09a
commit d499071d23
No known key found for this signature in database
GPG key ID: 02BA666D8C0E7E1B

View file

@ -323,14 +323,16 @@ export default class MediaDbPlugin extends Plugin {
fileContent = `---\n${this.settings.useCustomYamlStringifier ? YAMLConverter.toYaml(fileMetadata) : stringifyYaml(fileMetadata)}---\n` + fileContent;
return fileContent;
} else {
const parts = template.split('---');
const frontMatterRegex = /^---*\n([\s\S]*?)\n---\h*/;
if (parts.length < 3) {
const match = template.match(frontMatterRegex);
if (!match || match.length !== 2) {
throw new Error('Cannot find YAML front matter for template.');
}
let frontMatter = parseYaml(parts[1]);
let fileContent: string = parts[2];
let frontMatter = parseYaml(match[1]);
let fileContent: string = template.replace(frontMatterRegex, '');
// Updating a previous file
if (options.attachFile) {