diff --git a/lua/dotvim/pkgs/editor/plugins/obsidian.lua b/lua/dotvim/pkgs/editor/plugins/obsidian.lua index d330dd3a..a819610b 100644 --- a/lua/dotvim/pkgs/editor/plugins/obsidian.lua +++ b/lua/dotvim/pkgs/editor/plugins/obsidian.lua @@ -77,12 +77,18 @@ return { }, use_advanced_uri = true, mappings = {}, - note_id_func = function(_) - return ("%0x-%04x-%4x"):format( - os.time(), - math.random(0, 0xffff), - math.random(0, 0xffff) - ) + note_id_func = function(title) + local suffix = "" + if title ~= nil then + -- If title is given, transform it into valid file name. + suffix = title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower() + else + -- If title is nil, just add 4 random uppercase letters to the suffix. + for _ = 1, 4 do + suffix = suffix .. string.char(math.random(65, 90)) + end + end + return tostring(os.time()) .. "-" .. suffix end, note_frontmatter_func = function(note) local out = {