Replies: 2 comments 4 replies
-
Hey @jmrussell, you could accomplish this by configuring a callbacks = {
-- Runs right before writing the buffer for a note.
---@param client obsidian.Client
---@param note obsidian.Note
---@diagnostic disable-next-line: unused-local
pre_write_note = function(client, note)
note:add_field("modified", os.date())
end,
}, |
Beta Was this translation helpful? Give feedback.
1 reply
-
I use these to create more field such as modified and created_at on my frontmatter function -- Optional, alternatively you can customize the frontmatter data.
---@return table
note_frontmatter_func = function(note)
-- Add the title of the note as an alias.
if note.title then
note:add_alias(note.title)
end
local out = {
id = note.id,
aliases = note.aliases,
tags = note.tags,
}
-- add date only on init
local getDate = function(metadata)
local date = os.date "%Y-%m-%d"
if metadata == nil then
return date
end
return metadata.date
end
local getHubs = function(metadata)
local hubs = "[[]]"
if metadata == nil then
return hubs
end
return metadata.hubs
end
local getRefs = function(metadata)
local refs = "[[]]"
if metadata == nil then
return refs
end
return metadata.refs
end
note.metadata = {
date = getDate(note.metadata),
-- last_edited = os.date "%Y %B %d",
last_edited = os.date "%Y-%m-%d",
hubs = getHubs(note.metadata),
refs = getRefs(note.metadata),
}
-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
return out
end,
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way with the plugin (or another recommended, obsidian friendly way) to record the timestamp a note was created or last modified?
I'm new to the whole obsidian space but I've used nvim for a long time -- I think I could just write an autocmd that writes that information somewhere within the note, but I'd be interested if there's a better solution. Please let me know if I missed a similar discussion, somewhere, I did look but didn't find much.
Really enjoying this plugin, thanks for the great work!
Beta Was this translation helpful? Give feedback.
All reactions