Ultisnips snippet for generating Hugo TOML front matter header

· by Raghu Rajagopalan · Read in about 1 min · (84 words) ·

Here’s a small Ultisnips snippet for creating a TOML front matter header for Hugo

snippet post "blog post"
+++
author = "Raghu Rajagopalan"
date = "`!v strftime("%FT%H:%M:%S").strftime("%z")[:2].":" . strftime("%z")[3:]`"
publishdate = "`!v strftime("%FT%H:%M:%S").strftime("%z")[:2].":" . strftime("%z")[3:]`"
tags = ["easyblogger", "blogging"]
title = "${1:title}"
lastmod = "`!v strftime("%FT%H:%M:%S").strftime("%z")[:2].":" . strftime("%z")[3:]`"
+++

$0
endsnippet

To update the last modified date on save, put this little autocmd in your .vimrc

augroup AsciiDoc
    au!
    autocmd FileType asciidoc au BufWritePre <buffer>
                \ :silent 1,20s/^lastmod\s*=\s*".*"/\="lastmod = \"". strftime("%FT%H:%M:%S").strftime("%z")[:2]. ":".strftime("%z")[3:]."\""/e
augroup END