Skip to content

Commit

Permalink
Remove the existing article blocks and insert new one if it is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Jun 24, 2022
1 parent 9c4167a commit 19f70f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockEntity>(`"${slug}"`)
if (existingBlocks && existingBlocks.length > 0) {

This comment has been minimized.

Copy link
@wingy3181

wingy3181 Jun 24, 2022

Contributor

NIT: I think you could have used

if (existingBlocks?.length > 0) {

since undefined > 0 is false

This comment has been minimized.

Copy link
@sywhb

sywhb Jun 27, 2022

Author Collaborator

Yeah this should work. It's just in Typescript, there will be a type error if we compare undefined > 0

console.log(existingBlocks)

This comment has been minimized.

Copy link
@wingy3181

wingy3181 Jun 24, 2022

Contributor

NIT: would be good somehow to strip this out during the build if you instead to leave them in the source for debugging
would need figure out how to do that using parcel though

for (const block of existingBlocks) {
await logseq.Editor.removeBlock(block.uuid)
}
}

const articleBlock = await logseq.Editor.insertBlock(
targetBlock.uuid,
content,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 19f70f2

Please sign in to comment.