add mdxUpdateDate() to misc

This commit is contained in:
sup39 2023-02-26 00:19:46 +09:00
parent 0d72136ffd
commit 26c91a6c52

21
misc.vim Normal file
View file

@ -0,0 +1,21 @@
func s:mdxUpdateDate()
" guard ---
if getline(1) != "---" | return | endif
" find end ---
let lineEnd = search('\v%>1l^---$', 'n')
if lineEnd == 0 | return | endif
" prepare
let now = strftime('%Y/%m/%d(%a) %H:%M:%S')
let patpfx = '\v%>1l%<'.lineEnd.'l'
" createdAt
let line = search(patpfx.'^createdAt:\s*$', 'n')
if line > 0 | call setline(line, 'createdAt: '.now) | endif
" createdAt
let line = search(patpfx.'^updatedAt:', 'n')
if line > 0 | call setline(line, 'updatedAt: '.now) | endif
endfunc
augroup sup39_vimrc_misc
au!
au BufWritePre *.mdx call <SID>mdxUpdateDate()
augroup END