From 82dc4591161d0bcfefdf909bd05ff6fc3423a5f3 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 12 Sep 2022 19:03:06 +0800 Subject: [PATCH] fix: query to find existing blocks --- src/index.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6456df3..643f6b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -183,23 +183,16 @@ const fetchOmnivore = async (inBackground = false) => { let isNewArticle = true // update existing block if article is already in the page - const existingBlock = await logseq.DB.datascriptQuery( - `{:query - [:find (pull ?b [*]) - :in $ ?pattern - :where - [?b :block/content ?c] - [(re-pattern ?pattern) ?q] - [(re-find ?q ?c)]] - :inputs ["${article.slug}"]}` + const existingBlocks = await logseq.DB.q( + `"${article.slug}"` ) - if (existingBlock) { + if (existingBlocks && existingBlocks.length > 0) { isNewArticle = false // update existing block - await logseq.Editor.updateBlock(existingBlock.uuid, content) + await logseq.Editor.updateBlock(existingBlocks[0].uuid, content) highlightBatch.length > 0 && (await logseq.Editor.insertBatchBlock( - existingBlock.uuid, + existingBlocks[0].uuid, highlightBatch )) }