mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
make uuid more robust
This commit is contained in:
@@ -242,6 +242,8 @@ require('telekasten').setup({
|
||||
prefix_title_by_uuid = false,
|
||||
-- file uuid type ("rand" or input for os.date()")
|
||||
uuid_type = "%Y%m%d%H%M",
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
|
||||
@@ -68,9 +68,12 @@ telekasten.setup({opts})
|
||||
extension = ".md",
|
||||
|
||||
-- prefix file with uuid
|
||||
prefix_title_by_uuid = true,
|
||||
prefix_title_by_uuid = false,
|
||||
-- file uuid type ("rand" or input for os.date such as "%Y%m%d%H%M")
|
||||
uuid_type = "%Y%m%d%H%M",
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
|
||||
|
||||
templates = '/path/to/directory', -- path to templates
|
||||
extension = '.file extension', -- file extension of note files
|
||||
@@ -200,6 +203,12 @@ telekasten.setup({opts})
|
||||
|
||||
Default: '%Y%m%d%H%M'
|
||||
|
||||
*telekasten.settings.uuid_sep*
|
||||
uuid_sep: ~
|
||||
Separator between UUID and title in filaneme.
|
||||
|
||||
Default: '-'
|
||||
|
||||
*telekasten.settings.image_subdir*
|
||||
image_subdir: ~
|
||||
Path to the directory where pasted images should go to. Accepts
|
||||
|
||||
@@ -56,6 +56,8 @@ M.Cfg = {
|
||||
prefix_title_by_uuid = false,
|
||||
-- file uuid type ("rand" or input for os.date()")
|
||||
uuid_type = "%Y%m%d%H%M",
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
@@ -157,7 +159,7 @@ local function random_variable(length)
|
||||
return res
|
||||
end
|
||||
|
||||
local function getuuid(opts)
|
||||
local function get_uuid(opts)
|
||||
opts.prefix_title_by_uuid = opts.prefix_title_by_uuid
|
||||
or M.Cfg.prefix_title_by_uuid
|
||||
opts.uuid_type = opts.uuid_type or M.Cfg.uuid_type
|
||||
@@ -173,6 +175,15 @@ local function getuuid(opts)
|
||||
return uuid
|
||||
end
|
||||
|
||||
local function concat_uuid_title(uuid, title)
|
||||
local sep = M.Cfg.uuid_sep or "-"
|
||||
if uuid == nil then
|
||||
return title
|
||||
else
|
||||
return uuid .. sep .. title
|
||||
end
|
||||
end
|
||||
|
||||
local function print_error(s)
|
||||
vim.cmd("echohl ErrorMsg")
|
||||
vim.cmd("echomsg " .. '"' .. s .. '"')
|
||||
@@ -498,6 +509,9 @@ local function linesubst(line, title, dates, uuid)
|
||||
if dates == nil then
|
||||
dates = calculate_dates()
|
||||
end
|
||||
if uuid == nil then
|
||||
uuid = ""
|
||||
end
|
||||
|
||||
local substs = {
|
||||
hdate = dates.hdate,
|
||||
@@ -1834,8 +1848,11 @@ local function on_create_with_template(opts, title)
|
||||
opts.new_note_location = opts.new_note_location or M.Cfg.new_note_location
|
||||
opts.template_handling = opts.template_handling or M.Cfg.template_handling
|
||||
|
||||
local uuid = getuuid(opts)
|
||||
local pinfo = Pinfo:new({ title = uuid .. "-" .. title, opts })
|
||||
local uuid = get_uuid(opts)
|
||||
local pinfo = Pinfo:new({
|
||||
title = concat_uuid_title(uuid, title),
|
||||
opts,
|
||||
})
|
||||
local fname = pinfo.filepath
|
||||
if pinfo.fexists == true then
|
||||
-- open the new note
|
||||
@@ -1909,8 +1926,11 @@ local function on_create(opts, title)
|
||||
return
|
||||
end
|
||||
|
||||
local uuid = getuuid(opts)
|
||||
local pinfo = Pinfo:new({ title = uuid .. "-" .. title, opts })
|
||||
local uuid = get_uuid(opts)
|
||||
local pinfo = Pinfo:new({
|
||||
title = concat_uuid_title(uuid, title),
|
||||
opts,
|
||||
})
|
||||
local fname = pinfo.filepath
|
||||
|
||||
if pinfo.fexists ~= true then
|
||||
@@ -1929,7 +1949,7 @@ local function on_create(opts, title)
|
||||
find_files_sorted({
|
||||
prompt_title = "Created note...",
|
||||
cwd = pinfo.root_dir,
|
||||
default_text = uuid .. "-" .. title,
|
||||
default_text = concat_uuid_title(uuid, title),
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
@@ -2063,7 +2083,7 @@ local function FollowLink(opts)
|
||||
end
|
||||
|
||||
if #pinfo.filepath > 0 then
|
||||
local uuid = getuuid()
|
||||
local uuid = get_uuid(opts)
|
||||
create_note_from_template(
|
||||
title,
|
||||
uuid,
|
||||
|
||||
Reference in New Issue
Block a user