From d7c432167f6d92b920026cc400297fc78ddabfdb Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 24 Jan 2024 12:28:19 +0000 Subject: [PATCH] Set up normal obsidian naming conventions --- lua/core/plugin_config/obsidian.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/core/plugin_config/obsidian.lua b/lua/core/plugin_config/obsidian.lua index 075c1d7..8c248e0 100644 --- a/lua/core/plugin_config/obsidian.lua +++ b/lua/core/plugin_config/obsidian.lua @@ -20,4 +20,18 @@ require("obsidian").setup({ -- A map for custom variables, the key should be the variable and the value a function substitutions = {}, }, + 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 suffix + end, + })