alangrainger / obsidian-frontmatter-modified-date

Automatically update a frontmatter/YAML modified date field
MIT License
63 stars 10 forks source link

Related to #27 - keeps adding new modification dates on top #28

Closed ricir closed 1 month ago

ricir commented 1 month ago

When using the new inverse sort order, the plugin keeps adding new modification dates (on top as required).

modifiedDateTime:
  - 2024-08-12 16:51
  - 2024-08-12 16:51
  - 2024-08-12 16:50
  - 2024-08-12 16:50
  - 2024-08-11 17:23
append_modified_update: true

image

alangrainger commented 1 month ago

I can see the issue - fixing now :+1:

alangrainger commented 1 month ago

Fixed in 1.4.1, please let me know

ricir commented 1 month ago

OK it's working now! I'll need to rearrange the old lists in reverse order.

alangrainger commented 1 month ago

Excellent!

For your existing notes, you can put this in a Templater template or CustomJS action, assign it to a hotkey, and then hit the hotkey every time you come across a note with them in the wrong order:

<%*
app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
  frontmatter.modifiedDateTime.reverse()
})
-%>
ricir commented 1 month ago

Perfect!

I ended up in a slightly modified version of your proposed template, in order to also deal with files with dates not sorted for any reason:

<%*
app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
  frontmatter.modifiedDateTime.sort()
})
app.fileManager.processFrontMatter(tp.config.target_file, frontmatter => {
  frontmatter.modifiedDateTime.reverse()
})
-%>