From c5ff1fd608115cc4358eeace3cc047cc8b2a1f28 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Sun, 29 Dec 2024 15:24:22 -0800 Subject: [PATCH] feat: add workspace detection functionality to obsidian.nvim --- lua/plugins/lz-spec.lua | 1 + lua/plugins/obsidian.lua | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lua/plugins/obsidian.lua diff --git a/lua/plugins/lz-spec.lua b/lua/plugins/lz-spec.lua index 4f674b6..be3b37f 100644 --- a/lua/plugins/lz-spec.lua +++ b/lua/plugins/lz-spec.lua @@ -13,6 +13,7 @@ return { require("plugins.toggleterm"), require("plugins.by-lang.latex"), require("plugins.neogit"), + require("plugins.obsidian"), { "vim-wakatime" }, { "clangd_extensions.nvim" }, { "vim-sleuth" }, diff --git a/lua/plugins/obsidian.lua b/lua/plugins/obsidian.lua new file mode 100644 index 0000000..b95d951 --- /dev/null +++ b/lua/plugins/obsidian.lua @@ -0,0 +1,45 @@ +local function get_workspaces() + local all_workspaces = { + { + name = "vault", + path = vim.fs.normalize("~/Documents/vaults/vault"), + }, + { + name = "alexandria", + path = vim.fs.normalize("~/Documents/alexandria/content"), + }, + } + + local existing_workspaces = {} + + for i, x in ipairs(all_workspaces) do + if vim.fn.isdirectory(x.path) == 1 then + table.insert(existing_workspaces, all_workspaces[i]) + vim.notify( + [[Detected Obsidian workspace ]] + .. x.path + .. [[, adding ]] + .. vim.inspect(all_workspaces[i]) + .. [[ to obsidian workspaces]], + vim.log.levels.DEBUG + ) + end + end + + return existing_workspaces +end + +return { + "obsidian.nvim", + ft = { "markdown" }, + after = function() + local workspaces = get_workspaces() + + if #workspaces > 0 then + require("obsidian").setup({ + ui = { enable = false }, + workspaces = workspaces, + }) + end + end, +}