From 19f70f2bcf47eab1172134da38521566ccf68421 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 24 Jun 2022 22:41:24 +0800 Subject: [PATCH] Remove the existing article blocks and insert new one if it is updated --- index.ts | 9 +++++++++ package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 01ae96c..4ad4fb0 100644 --- a/index.ts +++ b/index.ts @@ -124,6 +124,15 @@ const fetchOmnivore = async ( date:: ${new Date(savedAt).toDateString()} > ${description}` + // remove existing block for the same article + const existingBlocks = await logseq.DB.q(`"${slug}"`) + if (existingBlocks && existingBlocks.length > 0) { + console.log(existingBlocks) + for (const block of existingBlocks) { + await logseq.Editor.removeBlock(block.uuid) + } + } + const articleBlock = await logseq.Editor.insertBlock( targetBlock.uuid, content, diff --git a/package.json b/package.json index 425bc56..a46acd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logseq-omnivore", - "version": "1.4.2", + "version": "1.4.3", "description": "Import Omnivore highlights and articles into Logseq.", "main": "dist/index.html", "targets": {