Skip to content

Commit

Permalink
fix: failed to sync articles to an existing file without front matter
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Jun 7, 2023
1 parent d0bb535 commit 58dbf98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
6 changes: 2 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 58dbf98

Please sign in to comment.