diff --git a/src/main.ts b/src/main.ts index e0a35c9..25af864 100644 --- a/src/main.ts +++ b/src/main.ts @@ -271,10 +271,11 @@ export default class OmnivorePlugin extends Plugin { const existingContentWithoutFrontmatter = removeFrontMatterFromContent(existingContent); // get front matter from content - const existingFrontMatter = - parseFrontMatterFromContent(existingContent); + let existingFrontMatter = + parseFrontMatterFromContent(existingContent) || []; if (!existingFrontMatter || !Array.isArray(existingFrontMatter)) { - throw new Error("Front matter does not exist in the note"); + // convert front matter to array + existingFrontMatter = [existingFrontMatter]; } const newFrontMatter = parseFrontMatterFromContent(content); if ( diff --git a/src/util.ts b/src/util.ts index 49d1850..84398ae 100644 --- a/src/util.ts +++ b/src/util.ts @@ -140,16 +140,14 @@ export const formatHighlightQuote = ( }; export const findFrontMatterIndex = ( - frontMatter: { id: string }[], + frontMatter: any[], id: string ): number => { // find index of front matter with matching id return frontMatter.findIndex((fm) => fm.id == id); }; -export const parseFrontMatterFromContent = ( - content: string -): unknown | undefined => { +export const parseFrontMatterFromContent = (content: string) => { // get front matter yaml from content const frontMatter = content.match(/^---\n(.*?)\n---/s); if (!frontMatter) {