mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Add UUID prefix to new notes
This commit is contained in:
@@ -238,6 +238,11 @@ require('telekasten').setup({
|
|||||||
-- markdown file extension
|
-- markdown file extension
|
||||||
extension = ".md",
|
extension = ".md",
|
||||||
|
|
||||||
|
-- prefix file with uuid
|
||||||
|
prefix_title_by_uuid = false,
|
||||||
|
-- file uuid type ("rand" or input for os.date()")
|
||||||
|
uuid_type = "%Y%m%d%H%M",
|
||||||
|
|
||||||
-- following a link to a non-existing note will create it
|
-- following a link to a non-existing note will create it
|
||||||
follow_creates_nonexisting = true,
|
follow_creates_nonexisting = true,
|
||||||
dailies_create_nonexisting = true,
|
dailies_create_nonexisting = true,
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ telekasten.setup({opts})
|
|||||||
-- markdown file extension
|
-- markdown file extension
|
||||||
extension = ".md",
|
extension = ".md",
|
||||||
|
|
||||||
|
-- prefix file with uuid
|
||||||
|
prefix_title_by_uuid = true,
|
||||||
|
-- file uuid type ("rand" or input for os.date such as "%Y%m%d%H%M")
|
||||||
|
uuid_type = "%Y%m%d%H%M",
|
||||||
|
|
||||||
templates = '/path/to/directory', -- path to templates
|
templates = '/path/to/directory', -- path to templates
|
||||||
extension = '.file extension', -- file extension of note files
|
extension = '.file extension', -- file extension of note files
|
||||||
|
|
||||||
@@ -182,6 +187,19 @@ telekasten.setup({opts})
|
|||||||
|
|
||||||
Default: '.md'
|
Default: '.md'
|
||||||
|
|
||||||
|
*telekasten.settings.prefix_title_by_uuid*
|
||||||
|
prefix_title_by_uuid: ~
|
||||||
|
Adds an Universal Unique Identifier before the file name.
|
||||||
|
|
||||||
|
Default: 'false'
|
||||||
|
|
||||||
|
*telekasten.settings.uuid_type*
|
||||||
|
uuid_type: ~
|
||||||
|
Type of UUID. Could be 'rand' for a random 6 character string, or a
|
||||||
|
time format to input in os.date() such as %Y%m%d%H%M.
|
||||||
|
|
||||||
|
Default: '%Y%m%d%H%M'
|
||||||
|
|
||||||
*telekasten.settings.image_subdir*
|
*telekasten.settings.image_subdir*
|
||||||
image_subdir: ~
|
image_subdir: ~
|
||||||
Path to the directory where pasted images should go to. Accepts
|
Path to the directory where pasted images should go to. Accepts
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ M.Cfg = {
|
|||||||
-- markdown file extension
|
-- markdown file extension
|
||||||
extension = ".md",
|
extension = ".md",
|
||||||
|
|
||||||
|
-- prefix file with uuid
|
||||||
|
prefix_title_by_uuid = false,
|
||||||
|
-- file uuid type ("rand" or input for os.date()")
|
||||||
|
uuid_type = "%Y%m%d%H%M",
|
||||||
|
|
||||||
-- following a link to a non-existing note will create it
|
-- following a link to a non-existing note will create it
|
||||||
follow_creates_nonexisting = true,
|
follow_creates_nonexisting = true,
|
||||||
dailies_create_nonexisting = true,
|
dailies_create_nonexisting = true,
|
||||||
@@ -143,6 +148,32 @@ local function file_exists(fname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function random_variable(length)
|
||||||
|
math.randomseed(os.clock() ^ 5)
|
||||||
|
local res = ""
|
||||||
|
for _ = 1, length do
|
||||||
|
res = res .. string.char(math.random(97, 122))
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
local function append_uuid(opts, title)
|
||||||
|
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
|
||||||
|
|
||||||
|
if opts.prefix_title_by_uuid then
|
||||||
|
local uuid = ""
|
||||||
|
if opts.uuid_type ~= "rand" then
|
||||||
|
uuid = os.date(opts.uuid_type)
|
||||||
|
else
|
||||||
|
uuid = random_variable(6)
|
||||||
|
end
|
||||||
|
title = uuid .. "-" .. title
|
||||||
|
end
|
||||||
|
return title
|
||||||
|
end
|
||||||
|
|
||||||
local function print_error(s)
|
local function print_error(s)
|
||||||
vim.cmd("echohl ErrorMsg")
|
vim.cmd("echohl ErrorMsg")
|
||||||
vim.cmd("echomsg " .. '"' .. s .. '"')
|
vim.cmd("echomsg " .. '"' .. s .. '"')
|
||||||
@@ -1793,6 +1824,8 @@ local function on_create_with_template(opts, title)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
title = append_uuid(opts, title)
|
||||||
|
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.insert_after_inserting = opts.insert_after_inserting
|
opts.insert_after_inserting = opts.insert_after_inserting
|
||||||
or M.Cfg.insert_after_inserting
|
or M.Cfg.insert_after_inserting
|
||||||
@@ -1874,6 +1907,8 @@ local function on_create(opts, title)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
title = append_uuid(opts, title)
|
||||||
|
|
||||||
local pinfo = Pinfo:new({ title = title, opts })
|
local pinfo = Pinfo:new({ title = title, opts })
|
||||||
local fname = pinfo.filepath
|
local fname = pinfo.filepath
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user