fixed denote directory support
This commit is contained in:
@@ -10,27 +10,28 @@ function denote#meta#fileFromNoteId(noteId)
|
||||
" (A) First, we get all files that contain the note id as substring.
|
||||
" (B) Then we ensure that the note id is followed by another field or by the
|
||||
" file extension.
|
||||
" TODO: Fix the following (now, we have full paths!)
|
||||
let files = glob(t:denote_directory .. "*" .. a:noteId .. "*", 0, v:true)
|
||||
\ ->filter('v:val =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"')
|
||||
\ ->filter('v:val =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"')
|
||||
\ ->filter('v:val->split("/")[-1] =~ "' .. a:noteId .. '\\(==\\|--\\|__\\|\\.\\)"')
|
||||
\ ->filter('v:val->split("/")[-1] =~ "^' .. a:noteId .. '\\|@@' .. a:noteId .. '"')
|
||||
return empty(files) ? v:false : files[0]
|
||||
endfunction
|
||||
|
||||
" Return the note id from the filename. On failure, v:false is returned.
|
||||
function denote#meta#noteIdFromFile(filename)
|
||||
return a:filename->matchstr("@@\\zs.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
||||
\ ?? a:filename->matchstr("^.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
||||
function denote#meta#noteIdFromFile(file)
|
||||
return a:file->fnamemodify(':t')->matchstr("@@\\zs.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
||||
\ ?? a:file->fnamemodify(':t')->matchstr("^.\\{-\\}\\ze\\(==\\|--\\|__\\|\\..\\)")
|
||||
\ ?? v:false
|
||||
endfunction
|
||||
|
||||
" Return the note title from the filename.
|
||||
function denote#meta#noteTitleFromFile(filename)
|
||||
return a:filename->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g")
|
||||
function denote#meta#noteTitleFromFile(file)
|
||||
return a:file->fnamemodify(':t')->matchstr("--\\zs.\\{-\\}\\ze\\(==\\|@@\\|__\\|\\..\\)")->substitute("-", " ", "g")
|
||||
endfunction
|
||||
|
||||
" Return the note tags from the filename as a list.
|
||||
function denote#meta#noteTagsFromFile(filename)
|
||||
return a:filename->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_")
|
||||
function denote#meta#noteTagsFromFile(file)
|
||||
return a:file->fnamemodify(':t')->matchstr("__\\zs.\\{-\\}\\ze\\(==\\|@@\\|--\\|\\..\\)")->split("_")
|
||||
endfunction
|
||||
|
||||
" Identifier creation
|
||||
|
||||
Reference in New Issue
Block a user