Last active
January 1, 2018 07:06
-
-
Save fourside/d09cbf3a755e292e977e31e592a7ee09 to your computer and use it in GitHub Desktop.
to create a post file of jekyll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim global plugin for creating jekyll's post | |
" Last Change: 2018 Jun 01 | |
" Maintainer: fourside <fourside@gmail.com> | |
" License: This file is placed in the public domain. | |
if exists("g:loaded_jekyll_post") | |
finish | |
endif | |
let g:loaded_jekyll_post = 1 | |
let s:save_cpo = &cpo | |
set cpo&vim | |
let s:zone_offset = strftime('%z') | |
if has('win32') | |
let s:zone_offset = '+0900' | |
endif | |
let s:template = [ | |
\ "---", | |
\ "layout: post", | |
\ "title: \"\"", | |
\ "date: " . strftime('%Y-%m-%d %H:%M:%S ') . s:zone_offset, | |
\ "categories: ", | |
\ "---", | |
\] | |
function! s:JekyllPost(...) | |
" variable-length args ignores a delimiter when joining | |
let title = join(split(join(a:000), " "), "-") | |
let filename = strftime('%Y-%m-%d-') . l:title . '.md' | |
execute ':edit ' . filename | |
if getfsize(filename) > 0 | |
return | |
endif | |
call append(0, s:template) | |
endfunction | |
if !exists(":JekyllPost") | |
command -nargs=1 JekyllPost :call s:JekyllPost(<q-args>) | |
endif | |
let &cpo = s:save_cpo | |
unlet s:save_cpo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment