michal-h21 / vim-zettel

VimWiki addon for managing notes according to Zettelkasten method
MIT License
555 stars 72 forks source link

Front Matter not included in YAML #117

Closed sebastianbock17 closed 2 years ago

sebastianbock17 commented 2 years ago

when I include front matter options, such as:

let g:zettel_options = [{"front_matter" : [["tags", ""], ["citation", ""]]}]

the result is just:

tags:
citation:
---
title: test2
date: 2021-12-12 14:40

How is it possible, to have tags and citation in the YAML?

My current solution is editing directly the vimwiki.vim

" title and date to a new zettel note
function! zettel#vimwiki#template(title, date)
  if g:zettel_disable_front_matter == 0
    call <sid>add_line(s:header_delimiter)
    call <sid>add_to_header("citation", "")
    call <sid>add_to_header("tags", "")
    call <sid>add_to_header("date", a:date)
    call <sid>add_to_header("title", a:title)
    call <sid>add_line(s:header_delimiter)
  endif
endfunction

I simply added 'call add_to_header("tags", "")' as the first option, resulting in:

---
title: test5
date: 2021-12-12 14:49
tags:
citation:
---

This is my current solution. Is there perhaps a better way of solving it in the plugin? Hope it might be helpful for others

heitorPB commented 2 years ago

This is what I have in my .vimrc:

let front_matter = {}
let front_matter.front_matter = {}
let front_matter.front_matter.keywords = []
let front_matter.front_matter.draft = "false"
let g:zettel_options = [front_matter]

this results in:

---
title: Example note
date: 2022-01-07 10:30
draft: false
keywords: []
---
sebastianbock17 commented 2 years ago

With your above example, I still get the following:

draft: false
keywords: []
---
title: test5
date: 2022-01-09 22:00
---

… while your above lines were the only configuration options included in my vimrc referring to vim-zettel, I have no idea what I'm doing wrong

Now I followed the advice by mihal, simply enabling the template and disabling the front matter, which gives me finally the result I was hoping for:

let g:zettel_options = [{"template" :  "~/scratchbox/vimwiki/mdtemplate.tpl", "disable_front_matter": 1}]

Originally posted by @michal-h21 in https://github.com/michal-h21/vim-zettel/issues/67#issuecomment-694835265

This way I can finally solely use the template that I can change ad hoc and customizable - which leads me to the next question - how to include the current ID , like %id ..., instead of %date (as %id is not defined) …

heitorPB commented 2 years ago

Do you have any other modification to vimwiki/vimzettel? Did you remove/revert your modification to vimwiki.vim?

sebastianbock17 commented 2 years ago

Yes, I have reverted / removed all my modifications (which were only the ones mentioned above) from vimwiki.vim, and still have the same issue - I had it from beginning on, retried with empty vimrcs several times, but at least now the old suggestion from @michal-h21 is working fine for me, which is the easiest and most flexible way in my opinion - to keep a template file at shorthand, editable if necessary to my likings with direct result. :)

I hope no other users deal with the same troubles - I dont know exactly why, but I have the opinion that my vimrc behaves illogical at times, as I am still a rookie in grasping how to work with it.

Nonetheless, many thanks to your efforts and support @heitorPB it is much appreciated, as I had almost given up with this issue and coincidentally still found the solution :)

heitorPB commented 2 years ago

It puzzles me that the same configuration gives a different output for us...

But I'm glad you managed to get it working somehow.