-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the existing article blocks and insert new one if it is updated
- Loading branch information
Showing
2 changed files
with
10 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sywhb
Author
Collaborator
|
||
console.log(existingBlocks) | ||
This comment has been minimized.
Sorry, something went wrong.
wingy3181
Contributor
|
||
for (const block of existingBlocks) { | ||
await logseq.Editor.removeBlock(block.uuid) | ||
} | ||
} | ||
|
||
const articleBlock = await logseq.Editor.insertBlock( | ||
targetBlock.uuid, | ||
content, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NIT: I think you could have used
if (existingBlocks?.length > 0) {
since undefined > 0 is false