Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ♻️ use process() method to write new content #43

Merged

Conversation

johannrichard
Copy link
Collaborator

Use the Vault.process() method to atomically read, modify, and save the contents of existing notes when updating from Readwise, instead of completely deleting and recreating the files. Should improve overall compatibility with other plugins, i.e. in the case of parallel edits.

The switch from getAbstractFileByPath() to getFileByPath() should simplify things without compromising functionalty.

Use the [`Vault.process()`](https://docs.obsidian.md/Reference/TypeScript+API/Vault/process) to atomically read, modify, and save the contents of existing notes when updating from Readwise, instead of completely deleting and recreating the files. Should improve overall compatibility with other plugins.

The switch from `getAbstractFileByPath()` to `getFileByPath()` should simplify things without compromising functionalty.
@johannrichard
Copy link
Collaborator Author

johannrichard commented Apr 8, 2024

N.B.: Besides making use of a standard API instead of deleting and recreating a file, changing to the process() method would in principle open the path to the following ideas as well:

  • Keep frontmatter for existing notes (or merge it, e.g. for updated fields), and
  • Attempt to merge local and remote changes (I am working on an approach for that, but it's a tricky thing), or, looking at requests like Partial note sections #24,
  • Other magic to properly manipulate the existing content.

Use `getAbstractFilebyPath()` instead of `getFileByPath()` to increase compatibility with older Obsidian versions. Bump ` obsidian` package version to `1.1.1`.
@jsonMartin
Copy link
Owner

@johannrichard good idea, I agree modification is a better strategy. Even if the markdown diff reconciliation solution doesn't pan out, this still looks like a better method to implement file modification operations.

@jsonMartin jsonMartin merged commit 994cfbb into jsonMartin:master May 20, 2024
Copy link

🎉 This PR is included in version 1.5.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants