20240818
This commit is contained in:
parent
74060df6ee
commit
d04d0cc51a
20 changed files with 359 additions and 114 deletions
44
global/.config/nvim/lua/utils/wiki_link.lua
Normal file
44
global/.config/nvim/lua/utils/wiki_link.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
local options = require("core.options")
|
||||
|
||||
local M = {}
|
||||
|
||||
local function generate_id(length)
|
||||
local chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
local id = ""
|
||||
for i = 1, length do
|
||||
local rand = math.random(#chars)
|
||||
id = id .. chars:sub(rand, rand)
|
||||
end
|
||||
return id
|
||||
end
|
||||
|
||||
local function file_exists(directory, filename)
|
||||
local filepath = directory .. "/" .. filename
|
||||
local file = io.open(filepath, "r")
|
||||
if file then
|
||||
io.close(file)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function generate_unique_id(directory, length)
|
||||
local id
|
||||
repeat
|
||||
id = generate_id(length)
|
||||
until not file_exists(directory, id .. ".md")
|
||||
return id
|
||||
end
|
||||
|
||||
function M.insert_link_with_unique_id()
|
||||
local id_length = 8
|
||||
|
||||
local unique_id = generate_unique_id(options.resources_dir, id_length)
|
||||
|
||||
local link = string.format("[name](%s.md)", unique_id)
|
||||
|
||||
vim.api.nvim_put({ link }, "c", true, true)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue