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

Don't write frontmatter to file if it is empty #480

Closed
UtkarshVerma opened this issue Mar 8, 2024 · 1 comment · Fixed by #482
Closed

Don't write frontmatter to file if it is empty #480

UtkarshVerma opened this issue Mar 8, 2024 · 1 comment · Fixed by #482
Labels

Comments

@UtkarshVerma
Copy link
Contributor

🚀 The feature, motivation and pitch

Currently, the plugin exposes note_frontmatter_func which is of the type fun(note:obsidian.Note):table. The table is prepended to the current buffer on save.

Now, when the table is empty, this results in an unnecessary addition of empty frontmatter at the top of the file.

---
---

Other text....

I think it would be more intuitive if we checked the returned table using vim.tbl_isempty() and only inject the frontmatter if it has some content.

Alternatives

To not affect the defaults, if that is desirable, we could change the type of note_frontmatter_func to fun(note:obsidian.Note):table?.

The nil value would indicate that there is no frontmatter and that it should be removed from the current file.

Additional context

No response

@epwalsh
Copy link
Owner

epwalsh commented Mar 8, 2024

@UtkarshVerma I agree this would make sense. If you want to make a PR, I believe you'd just have to modify Note:frontmatter_lines() to return an empty list when vim.tbl_isempty():

Note.frontmatter_lines = function(self, eol, frontmatter)

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

Successfully merging a pull request may close this issue.

2 participants