beaussan / update-time-on-edit-obsidian

MIT License
165 stars 15 forks source link

Rewrites blank frontmatter to be null #52

Closed doug-w closed 1 year ago

doug-w commented 1 year ago

I have a contact template that has fields like:

---
company:
location:
title:
email:
---

After editing a contact with this plugin enabled it becomes

---
company: null
location: null
title: null
email: null
updated: 2023-07-29T11:31
created: 2023-05-28T09:28
---

I expect only the created and updated fields to be changed and not every field that was blank

Buddinski88 commented 1 year ago

Thank you for opening that Bug, because i have the same issue with version 2.0.1 and also 2.0.2.

I have this set of frontmatter yaml:

---
tags: 🧠️/📝️/🌱️
type: "doc"
active: perhaps
publish: false
aliases: 
created: 2023-07-25 11:40
updated: 2023-07-29 20:06
---

When i for example change type: "doc" to type: doc then the frontmatterdata locks like this:

---
tags: 🧠️/📝️/🌱️
type: doc
active: perhaps
publish: false
aliases: null
created: 2023-07-25 11:40
updated: 2023-07-29 20:06
---

Deleting the null from "aliases" and add the quotationmarks like in the first example, then everything will be changed back as in the second example.

After i disable the plugin everything works fine.

Buddinski88 commented 1 year ago

Update: I have just tested with version 1.1.2 and there the frontmatter data are not simply changed. So everything except just created and updated.

beaussan commented 1 year ago

This is coming from obsidian own's api processFrontMatter, that tries to make valid yaml at every step, and thus, setting null instead of empty.

Given their answer on a previous topic related to the yaml formatting, I guess it's intended behaviour from their side. Feel free to open an issue on the obsidian api repo if you want to raise the concern !

planefun2 commented 1 year ago

Update: I have just tested with version 1.1.2 and there the frontmatter data are not simply changed. So everything except just created and updated.

So rolling back to 1.1.2 works for you?

beaussan commented 1 year ago

The change was introduced in 2.0 to prevent a bunch of bugs with metadata parsing & writing, so any version prior to it will not output null in empty frontmatter.

Again, if you are not happy with this behaviour, feel free to open an issue on the obsidian api repo where they can either fix it, or explain why it's the case.

FeralFlora commented 1 year ago

This auto-editing happens so often that it is disrupting my attempts to write yaml fields manually.

I was trying to create a field like this:

---
links:
- [[link1]]
- [[link2]]
___

But before I could make the link list, the plugin would disrupt my typing and input extra - and stuff like that. I had to disable the plugin.

beaussan commented 1 year ago

This auto-editing happens so often that it is disrupting my attempts to write yaml fields manually.

I was trying to create a field like this:

---
links:
- [[link1]]
- [[link2]]
___

But before I could make the link list, the plugin would disrupt my typing and input extra - and stuff like that. I had to disable the plugin.

@MSBack I would suggest you to use obsidian new property system if you have access to it, as 2.0.0 is compliant with it. If not, you can rollback to a previous version

FeralFlora commented 1 year ago

I would suggest you to use obsidian new property system if you have access to it, as 2.0.0 is compliant with it. If not, you can rollback to a previous version

I do have access, but it is not available on mobile yet (which I was using this time). Besides, source mode is still a valid way to edit notes and yaml. I think the plugin should respect that.

beaussan commented 1 year ago

This auto-editing happens so often that it is disrupting my attempts to write yaml fields manually.

This plugin now wait for at least one minute, and can be configured to wait for more in the setting, between updates. This should address part of the issue. I will do some test and raise an issue on Obsidian's side for the front matter

beaussan commented 1 year ago

@doug-w @Buddinski88 what version of Obsidian are you running ?

About the "doc" to doc, this is intended behaviour from Obsidian itself, see the linked comment.

Here is a recording from Obsidian v1.4.2, and the empty fields are not set to null. Like previously said, this is an Obsidian native API that handle this part of the code, and I don't have any control over it.

https://github.com/beaussan/update-time-on-edit-obsidian/assets/7281023/35d6b32e-bb61-45fb-bc4a-2c7e932137ec

Buddinski88 commented 1 year ago

@doug-w @Buddinski88 what version of Obsidian are you running ?

About the "doc" to doc, this is intended behaviour from Obsidian itself, see the linked comment.

Here is a recording from Obsidian v1.4.2, and the empty fields are not set to null. Like previously said, this is an Obsidian native API that handle this part of the code, and I don't have any control over it.

update-time-on-edit-headers.mp4

Thank you for the further analysis. In the video it looks like everything works as expected. I there assume that i have to wait until 1.4.X is available for public as well :-)

Addition: I use version 1.3.7.

beaussan commented 1 year ago

Given 1.4 has been released, this should now be fixed

doug-w commented 1 year ago

This does seem to be resolved for me and I'm using it again on all devices.