Obsidian Tips: Embedding Creation and Modification time in Front Matter of Notes
Updated: Oct 25th, 2023
By default, the Obsidian and others will not record the creation and modification time for notes. Instead, they rely on the file system of our laptop to track this information. However, this method has some drawbacks. I propose tracking the creation and modification time in the front matter of each note instead.
Reasons
- If we change our laptop or copy notes to another location, we will
lose the time information.
- Since these metadata are stored at the file system level, copying a file creates new files.
- Consequently, the created time and modified time will be incorrect.
- Many blog systems (such as Jekyll) can read metadata from the front
matter.
-
https://github.com/maximevaillancourt/jekyll-last-modified-at
can read
page.last_modified_at
- The default setup of jekyll blog
will read
page.date
as creation time.
-
https://github.com/maximevaillancourt/jekyll-last-modified-at
can read
- When the creation and modification time are in front matter, you can use plugin like dataview to get the most recent modified note and achieve other useful features !
My Setup
Goals
- Each time we store the node (or press
Ctrl+S
), thecreated_at
andlast_modified_at
fields in the front matter should be updated. - The
created_at
field should reflect the creation time of this note.- If the
created_at
field does not exist, automatic methods should read the creation time from the file system metadata and update this field in the front matter. - When the
created_at
field already exists, automatic methods should not update it any further.
- If the
- The
last_modified_at
field should reflect the most recent modification time.- When we modify a note, this field should be updated accordingly.
- However, if we do not make any modifications to a note and simply
press
Ctrl+S
, this field should remain unchanged.
- The format of time can be customized according to your needs.
TIPS: The name of field should fit your need. For example, many Jekyll plugins default to reading
page.date
for creation time. Since I usepage.created_at
, some adjustments are necessary.
How
To achieve the goal, we will use the platers/obsidian-linter plugin, which is easy to use.
Once you configure this plugin as shown in the picture below, it will be ready.
My setup of time format is yyyy-MM-DD HH:mm:ss Z