feat: add workspace detection functionality to obsidian.nvim

This commit is contained in:
Youwen Wu 2024-12-29 15:24:22 -08:00
parent dc61ca5949
commit c5ff1fd608
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
2 changed files with 46 additions and 0 deletions

View file

@ -13,6 +13,7 @@ return {
require("plugins.toggleterm"), require("plugins.toggleterm"),
require("plugins.by-lang.latex"), require("plugins.by-lang.latex"),
require("plugins.neogit"), require("plugins.neogit"),
require("plugins.obsidian"),
{ "vim-wakatime" }, { "vim-wakatime" },
{ "clangd_extensions.nvim" }, { "clangd_extensions.nvim" },
{ "vim-sleuth" }, { "vim-sleuth" },

45
lua/plugins/obsidian.lua Normal file
View file

@ -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,
}