- For new entries, add '#mdate {currentdate}' on the 2nd line.
- For existing entries without '#mdate' metadata, it will look up the mdate of the current entry and append it in the form, '#mdate {mdate of file}'
- After you write (:w, :wq, etc), vim will look for #mdate metadata and turn the date into something touch(1) can use, then set the modification date of the file.
My "vim scripting"-fu is not strong, so there's probably a cleaner/fancier way to do this. Anyhoo, you'll need the following in your .vimrc:
" PyBlosxom stuff
augroup pyblosxom
autocmd BufReadPost /home/jls/public_html/entries/*/*.txt call Pyblosxom_checkdate()
autocmd BufNewFile /home/jls/public_html/entries/*/*.txt call Pyblosxom_putdate()
autocmd BufWritePost /home/jls/public_html/entries/*/*.txt call Pyblosxom_fudgedate()
augroup end
function Pyblosxom_checkdate()
" Look in the file for '#mdate foo' metadata
normal 1G
let dateline = search("^#mdate")
" If not found, append the mdate of the file to line 2
if dateline < 1
let dateline = 1
let date = system("stat -f '#mdate %Sm' " . expand("%"))
" Add the date to the file on line 1
1put=date
endif
endfunction
function Pyblosxom_putdate()
let date=strftime("#mdate %b %e %H:%M:%S %Y")
1put=date
goto 1
endfunction
function Pyblosxom_fudgedate()
let l=search("^#mdate")
let l=strpart(getline(l), 7)
let cmd="date -j -f '%b %e %H:%M:%S %Y' '" . l . "' +%y%m%d%H%M"
let touchtime=system(cmd)
let touchcmd="touch -t '" . strpart(touchtime,0,strlen(touchtime)-1) . "' '" . expand("%") . "'"
call system(touchcmd)
e
endfunction