Support new and old frontmatter api#100
Conversation
|
|
||
| //@ts-ignore - this is part of the new Obsidian API as of v1.4.1 | ||
| const {start, end} = fileCache?.frontmatterPosition; | ||
| const {start, end} = fileCache?.frontmatterPosition ?? fileCache?.frontmatter?.position; |
There was a problem hiding this comment.
This isn't ideal because if anything's null/undefined then destructuring will throw an exception, but that would happen even before this change.
FYI: v1.4.0 of the obsidian types includes both of these properties now obsidianmd/obsidian-api@90517f4
|
After some more testing this doesn't look like a full fix. I need to debug it some more to see what else needs to be adjusted. |
|
What was happening is on desktop unset values were remaining unset, but on mobile they were coming through as a literal string of |
| const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition; | ||
|
|
||
| if (property.type === MetaType.YAML && frontmatterPosition) { | ||
| const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}\n---`; |
There was a problem hiding this comment.
| const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}\n---`; | |
| const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}---`; |
On both desktop & mobile an extra blank line is being added to the frontmatter because of this \n. I removed it in my local copy but wasn't sure if it should be part of this PR.
The current implementation works fine in the desktop app, but the mobile app still uses the old api. I patched my local copy and this seems to work on both now.
Fixes #99