mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
refact: file_extension
This commit is contained in:
@@ -892,14 +892,6 @@ function Pinfo:resolve_link(title, opts)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local function endswith(s, ending)
|
|
||||||
-- return ending == "" or s:sub(-#ending) == ending
|
|
||||||
-- end
|
|
||||||
|
|
||||||
local function file_extension(fname)
|
|
||||||
return fname:match("^.+(%..+)$")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function filter_filetypes(flist, ftypes)
|
local function filter_filetypes(flist, ftypes)
|
||||||
local new_fl = {}
|
local new_fl = {}
|
||||||
ftypes = ftypes or { M.Cfg.extension }
|
ftypes = ftypes or { M.Cfg.extension }
|
||||||
@@ -910,7 +902,7 @@ local function filter_filetypes(flist, ftypes)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, fn in pairs(flist) do
|
for _, fn in pairs(flist) do
|
||||||
if ftypeok[file_extension(fn)] then
|
if ftypeok[fileutils.get_extension(fn)] then
|
||||||
table.insert(new_fl, fn)
|
table.insert(new_fl, fn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ function M.file_exists(fname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the file extension
|
||||||
|
function M.get_extension(fname)
|
||||||
|
return fname:match("^.+(%..+)$")
|
||||||
|
end
|
||||||
|
|
||||||
-- Strips an extension from a file name, escaping "." properly, eg:
|
-- Strips an extension from a file name, escaping "." properly, eg:
|
||||||
-- strip_extension("path/Filename.md", ".md") -> "path/Filename"
|
-- strip_extension("path/Filename.md", ".md") -> "path/Filename"
|
||||||
local function strip_extension(str, ext)
|
local function strip_extension(str, ext)
|
||||||
|
|||||||
Reference in New Issue
Block a user