mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Add filename_space_subst config option (#198)
* add filename_space_subst configuration option * add docs for new filename_space_subst * fix template refactor bug
This commit is contained in:
@@ -312,6 +312,9 @@ require('telekasten').setup({
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
|
||||
-- if not nil, this string replaces spaces in the title when generating filenames
|
||||
filename_space_subst = nil,
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
dailies_create_nonexisting = true,
|
||||
|
||||
@@ -255,6 +255,19 @@ telekasten.setup({opts})
|
||||
|
||||
Default: '-'
|
||||
|
||||
*telekasten.settings.filename_space_subst*
|
||||
filename_space_subst: ~
|
||||
When the note title is used within the filename, i.e.
|
||||
|new_note_filename| contains 'title', spaces in the title will be
|
||||
substituted for |filename_space_subst|.
|
||||
|
||||
e.g. if set to '_', '20230103-my new note title.md' would instead
|
||||
become '20230103-my_new_note_title.md'
|
||||
|
||||
If set to `nil`, no substitution will occur.
|
||||
|
||||
Default: `nil`
|
||||
|
||||
*telekasten.settings.image_subdir*
|
||||
image_subdir: ~
|
||||
Path to the directory where pasted images should go to. Accepts
|
||||
|
||||
@@ -74,6 +74,9 @@ local function defaultConfig(home)
|
||||
-- UUID separator
|
||||
uuid_sep = "-",
|
||||
|
||||
-- if not nil, replaces any spaces in the title when it is used in filename generation
|
||||
filename_space_subst = nil,
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
dailies_create_nonexisting = true,
|
||||
@@ -224,6 +227,10 @@ local function get_uuid(opts)
|
||||
end
|
||||
|
||||
local function generate_note_filename(uuid, title)
|
||||
if M.Cfg.filename_space_subst ~= nil then
|
||||
title = escape(title):gsub(" ", M.Cfg.filename_space_subst)
|
||||
end
|
||||
|
||||
local pp = Path:new(title)
|
||||
local p_splits = pp:_split()
|
||||
local filename = p_splits[#p_splits]
|
||||
@@ -649,9 +656,9 @@ local function linesubst(line, title, dates, uuid)
|
||||
end
|
||||
|
||||
local substs = vim.tbl_extend("error", dates, {
|
||||
shorttitle,
|
||||
uuid,
|
||||
title,
|
||||
shorttitle = shorttitle,
|
||||
uuid = uuid,
|
||||
title = title,
|
||||
})
|
||||
|
||||
for k, v in pairs(substs) do
|
||||
|
||||
Reference in New Issue
Block a user