feat: adds wiki vim config with obsidian style link resolution
All checks were successful
gitea-deepak/nixconf/pipeline/head This commit looks good
All checks were successful
gitea-deepak/nixconf/pipeline/head This commit looks good
This commit is contained in:
parent
b673398888
commit
6263a9f3c3
@ -69,6 +69,8 @@
|
|||||||
lua << EOF
|
lua << EOF
|
||||||
require'lspconfig'.nil_ls.setup{}
|
require'lspconfig'.nil_ls.setup{}
|
||||||
${builtins.readFile ./neovim/wiki-vim.lua}
|
${builtins.readFile ./neovim/wiki-vim.lua}
|
||||||
|
|
||||||
|
EOF
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
-- vim.g.wiki_root = "/path/to/obsidian/vault"
|
vim.g.wiki_root = "/home/deepak/wiki"
|
||||||
vim.g.wiki_root = "~/wiki"
|
|
||||||
|
|
||||||
local function find_wiki_path_for_file(filename)
|
local function find_wiki_path_for_file(filename)
|
||||||
-- recursively search for the file name in the wiki_root using ripgrep
|
-- recursively search for the file name in the wiki_root using ripgrep
|
||||||
@ -26,29 +25,51 @@ end
|
|||||||
|
|
||||||
local function resolve_wiki_link(url)
|
local function resolve_wiki_link(url)
|
||||||
local components = {}
|
local components = {}
|
||||||
|
|
||||||
|
-- print(vim.inspect(url))
|
||||||
|
|
||||||
for element in (url.stripped .. "#"):gmatch("([^#]*)#") do
|
for element in (url.stripped .. "#"):gmatch("([^#]*)#") do
|
||||||
table.insert(components, element)
|
table.insert(components, element)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- print(vim.inspect(components))
|
||||||
|
-- print("spot A")
|
||||||
|
|
||||||
local filename = components[1]
|
local filename = components[1]
|
||||||
url.anchor = components[2] or ""
|
url.anchor = components[2] or ""
|
||||||
|
|
||||||
|
-- print("spot B")
|
||||||
|
|
||||||
-- infer the .md file extension
|
-- infer the .md file extension
|
||||||
if filename:sub(-3) ~= ".md" then filename = filename .. ".md" end
|
if filename:sub(-3) ~= ".md" then filename = filename .. ".md" end
|
||||||
|
|
||||||
if url.origin:sub(1, #vim.g.wiki_root) == vim.g.wiki_root then
|
-- print("spot C")
|
||||||
|
-- print(filename)
|
||||||
|
if (url.origin:sub(1, #vim.g.wiki_root) == vim.g.wiki_root) or url.origin == '' then
|
||||||
|
-- print("in the wiki root start block")
|
||||||
|
--
|
||||||
-- if the "origin" (the file that contains the link) is in the wiki_root,
|
-- if the "origin" (the file that contains the link) is in the wiki_root,
|
||||||
-- the wiki_root directory is recursively searched for the file name;
|
-- the wiki_root directory is recursively searched for the file name;
|
||||||
|
--
|
||||||
|
-- an empty origin, like you'd get from <leader>ww, is also mapped to this block
|
||||||
url.path = find_wiki_path_for_file(filename)
|
url.path = find_wiki_path_for_file(filename)
|
||||||
|
-- print("in the wiki root")
|
||||||
else
|
else
|
||||||
|
-- print("not in the wiki root start block")
|
||||||
-- if the origin is not in the wiki_root,
|
-- if the origin is not in the wiki_root,
|
||||||
-- fall back to only looking in the same directory as the origin
|
-- fall back to only looking in the same directory as the origin
|
||||||
url.path = url.origin:match(".*/") .. filename
|
url.path = url.origin:match(".*/") .. filename
|
||||||
|
-- print("not in the wiki root")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- print(vim.inspect(url))
|
||||||
|
|
||||||
return url
|
return url
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.g.wiki_link_schemes = {
|
vim.g.wiki_link_schemes = {
|
||||||
wiki = { resolver = resolve_wiki_link, },
|
wiki = {
|
||||||
|
resolver = resolve_wiki_link,
|
||||||
|
-- handler = function(x) print(vim.inspect(x)) end,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user