mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
feat: Add sorting feature [closes #85]
* feat: Add sorting feature #85 * fix: Remove the lines that should not be sorted
This commit is contained in:
@@ -271,6 +271,9 @@ require('telekasten').setup({
|
|||||||
-- markdown: 
|
-- markdown: 
|
||||||
image_link_style = "markdown",
|
image_link_style = "markdown",
|
||||||
|
|
||||||
|
-- default sort option: 'filename', 'modified'
|
||||||
|
sort = "filename",
|
||||||
|
|
||||||
-- integrate with calendar-vim
|
-- integrate with calendar-vim
|
||||||
plug_into_calendar = true,
|
plug_into_calendar = true,
|
||||||
calendar_opts = {
|
calendar_opts = {
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ telekasten.setup({opts})
|
|||||||
-- markdown: 
|
-- markdown: 
|
||||||
image_link_style = "wiki",
|
image_link_style = "wiki",
|
||||||
|
|
||||||
|
-- default sort option: 'filename', 'modified'
|
||||||
|
sort = "filename",
|
||||||
|
|
||||||
-- specific note templates
|
-- specific note templates
|
||||||
-- set to `nil` or do not specify if you do not want a template
|
-- set to `nil` or do not specify if you do not want a template
|
||||||
@@ -245,6 +247,16 @@ telekasten.setup({opts})
|
|||||||
|
|
||||||
Default: 'markdown'
|
Default: 'markdown'
|
||||||
|
|
||||||
|
*telekasten.settings.sort*
|
||||||
|
sort: ~
|
||||||
|
Order the notes by the option.
|
||||||
|
|
||||||
|
Valid options are:
|
||||||
|
- 'filename'
|
||||||
|
- 'modified'
|
||||||
|
|
||||||
|
Default: 'filename'
|
||||||
|
|
||||||
*telekasten.settings.follow_create_nonexisting*
|
*telekasten.settings.follow_create_nonexisting*
|
||||||
follow_creates_nonexisting: ~
|
follow_creates_nonexisting: ~
|
||||||
Flag that determines whether non-existing notes should be created when
|
Flag that determines whether non-existing notes should be created when
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ M.Cfg = {
|
|||||||
-- markdown: 
|
-- markdown: 
|
||||||
image_link_style = "markdown",
|
image_link_style = "markdown",
|
||||||
|
|
||||||
|
-- default sort option: 'filename', 'modified'
|
||||||
|
sort = "filename",
|
||||||
|
|
||||||
-- when linking to a note in subdir/, create a [[subdir/title]] link
|
-- when linking to a note in subdir/, create a [[subdir/title]] link
|
||||||
-- instead of a [[title only]] link
|
-- instead of a [[title only]] link
|
||||||
subdirs_in_links = true,
|
subdirs_in_links = true,
|
||||||
@@ -933,10 +936,6 @@ function Pinfo:resolve_link(title, opts)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
local function order_numeric(a, b)
|
|
||||||
return a > b
|
|
||||||
end
|
|
||||||
|
|
||||||
-- local function endswith(s, ending)
|
-- local function endswith(s, ending)
|
||||||
-- return ending == "" or s:sub(-#ending) == ending
|
-- return ending == "" or s:sub(-#ending) == ending
|
||||||
-- end
|
-- end
|
||||||
@@ -1013,7 +1012,16 @@ local function find_files_sorted(opts)
|
|||||||
local file_list = scan.scan_dir(opts.cwd, {})
|
local file_list = scan.scan_dir(opts.cwd, {})
|
||||||
local filter_extensions = opts.filter_extensions or M.Cfg.filter_extensions
|
local filter_extensions = opts.filter_extensions or M.Cfg.filter_extensions
|
||||||
file_list = filter_filetypes(file_list, filter_extensions)
|
file_list = filter_filetypes(file_list, filter_extensions)
|
||||||
table.sort(file_list, order_numeric)
|
local sort_option = opts.sort or "filename"
|
||||||
|
if sort_option == "modified" then
|
||||||
|
table.sort(file_list, function(a, b)
|
||||||
|
return vim.fn.getftime(a) > vim.fn.getftime(b)
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
table.sort(file_list, function(a, b)
|
||||||
|
return a > b
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
local counts = nil
|
local counts = nil
|
||||||
if opts.show_link_counts then
|
if opts.show_link_counts then
|
||||||
@@ -1322,6 +1330,7 @@ local function FindDailyNotes(opts)
|
|||||||
map("n", "<esc>", picker_actions.close(opts))
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1371,6 +1380,7 @@ local function FindWeeklyNotes(opts)
|
|||||||
map("n", "<esc>", picker_actions.close(opts))
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1422,6 +1432,7 @@ local function InsertLink(opts)
|
|||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
find_command = M.Cfg.find_command,
|
find_command = M.Cfg.find_command,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1506,6 +1517,7 @@ local function PreviewImg(opts)
|
|||||||
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
|
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
print("File not found: " .. M.Cfg.home .. "/" .. fname)
|
print("File not found: " .. M.Cfg.home .. "/" .. fname)
|
||||||
@@ -1556,6 +1568,7 @@ local function BrowseImg(opts)
|
|||||||
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
|
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1793,6 +1806,7 @@ local function FindNotes(opts)
|
|||||||
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
map("n", "<c-cr>", picker_actions.paste_link(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1843,6 +1857,7 @@ local function InsertImgLink(opts)
|
|||||||
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
|
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2204,6 +2219,7 @@ local function FollowLink(opts)
|
|||||||
map("n", "<esc>", picker_actions.close(opts))
|
map("n", "<esc>", picker_actions.close(opts))
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
sort = M.Cfg.sort,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user