rename notes/and files
This commit is contained in:
@@ -25,12 +25,22 @@ endfunction
|
||||
|
||||
" Return the note title from the filename.
|
||||
function denote#meta#noteTitleFromFile(file)
|
||||
return a:file->fnamemodify(':t')->matchstr('--\zs.\{-\}\ze\(==\|@@\|__\|\..\)')->substitute('-', ' ', 'g')
|
||||
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(file)
|
||||
return a:file->fnamemodify(':t')->matchstr('__\zs.\{-\}\ze\(==\|@@\|--\|\..\)')->split('_')
|
||||
return a:file->fnamemodify(':t')
|
||||
\ ->matchstr('__\zs.\{-\}\ze\(==\|@@\|--\|\..\)')
|
||||
\ ->split('_')
|
||||
endfunction
|
||||
|
||||
" Return the note signature from the filename.
|
||||
function denote#meta#noteSignatureFromFile(file)
|
||||
return a:file->fnamemodify(':t')
|
||||
\ ->matchstr('==\zs.\{-\}\ze\(==\|@@\|__\|\..\)')
|
||||
endfunction
|
||||
|
||||
" Identifier creation
|
||||
@@ -39,3 +49,24 @@ function denote#meta#identifier_generate()
|
||||
\ ? strftime('%Y%m%dT%H%M%S')
|
||||
\ : rand()
|
||||
endfunction
|
||||
|
||||
" This function removes illegal characters in parts of the filename.
|
||||
function s:santizefnpart(part)
|
||||
return a:part->tolower()
|
||||
\ ->substitute('[^[:alnum:]]', '-', 'g')
|
||||
\ ->substitute('-\+', '-', 'g')
|
||||
\ ->substitute('_\+', '_', 'g')
|
||||
\ ->substitute('=\+', '=', 'g')
|
||||
\ ->substitute('@\+', '@', 'g')
|
||||
\ ->trim('-_@=')
|
||||
endfunction
|
||||
|
||||
" Function that returns the filename give all metadata. The filename is
|
||||
" returned with the path to the denote directory.
|
||||
function denote#meta#filename(ext, identifier, title='', tags=[], signature='')
|
||||
let l:f = g:denote_directory .. '/' .. s:santizefnpart(a:identifier)
|
||||
let l:f ..= len(a:signature) > 0 ? ('==' .. s:santizefnpart(a:signature)) : ''
|
||||
let l:f ..= len(a:title) > 0 ? ('--' .. s:santizefnpart(a:title)) : ''
|
||||
let l:f ..= len(a:tags) > 0 ? ('__' .. map(copy(a:tags), {_, v -> s:santizefnpart(v)})->join('_')) : ''
|
||||
return l:f .. '.' .. a:ext
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user