Add custom function option for UUID generation (#194)

* add custom function option for UUID generation

* add docs for new UUID custom function option
This commit is contained in:
skovati
2023-01-02 11:27:38 +00:00
committed by GitHub
parent acc5f0e333
commit 8d3f97b729
3 changed files with 20 additions and 7 deletions

View File

@@ -302,7 +302,12 @@ require('telekasten').setup({
-- "uuid-title" - Prefix title by uuid -- "uuid-title" - Prefix title by uuid
-- "title-uuid" - Suffix title with uuid -- "title-uuid" - Suffix title with uuid
new_note_filename = "title", new_note_filename = "title",
-- file uuid type ("rand" or input for os.date()")
--[[ file UUID type
- "rand"
- string input for os.date()
- or custom lua function that returns a string
--]]
uuid_type = "%Y%m%d%H%M", uuid_type = "%Y%m%d%H%M",
-- UUID separator -- UUID separator
uuid_sep = "-", uuid_sep = "-",

View File

@@ -243,8 +243,9 @@ telekasten.setup({opts})
*telekasten.settings.uuid_type* *telekasten.settings.uuid_type*
uuid_type: ~ uuid_type: ~
Type of UUID. Could be 'rand' for a random 6 character string, or a Type of UUID. Could be 'rand' for a random 6 character string, a
time format to input in os.date() such as %Y%m%d%H%M. time format to input in os.date() such as '%Y%m%d%H%M', or any lua
function like os.time() that returns a string.
Default: '%Y%m%d%H%M' Default: '%Y%m%d%H%M'

View File

@@ -64,7 +64,12 @@ local function defaultConfig(home)
-- "uuid-title" - Prefix title by uuid -- "uuid-title" - Prefix title by uuid
-- "title-uuid" - Suffix title with uuid -- "title-uuid" - Suffix title with uuid
new_note_filename = "title", new_note_filename = "title",
-- file uuid type ("rand" or input for os.date()")
--[[ file UUID type
- "rand"
- string input for os.date()
- or custom lua function that returns a string
--]]
uuid_type = "%Y%m%d%H%M", uuid_type = "%Y%m%d%H%M",
-- UUID separator -- UUID separator
uuid_sep = "-", uuid_sep = "-",
@@ -208,10 +213,12 @@ local function get_uuid(opts)
opts.uuid_type = opts.uuid_type or M.Cfg.uuid_type opts.uuid_type = opts.uuid_type or M.Cfg.uuid_type
local uuid local uuid
if opts.uuid_type ~= "rand" then if opts.uuid_type == "rand" then
uuid = os.date(opts.uuid_type)
else
uuid = random_variable(6) uuid = random_variable(6)
elseif type(opts.uuid_type) == "function" then
uuid = opts.uuid_type()
else
uuid = os.date(opts.uuid_type)
end end
return uuid return uuid
end end