Skip to content

Commit

Permalink
Added g:jekyll_post_created to automatically add a strftime or epoch …
Browse files Browse the repository at this point in the history
…to the YAML matter for new posts
  • Loading branch information
claco authored and csexton committed Nov 7, 2010
1 parent b95c493 commit 1e861d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion doc/jekyll.txt
Expand Up @@ -16,11 +16,14 @@ Example:
let g:jekyll_path = "/path/to/jekyll/blog"

The default post suffix is "markdown" and the post status is published. You
can override these if you like.
can override these if you like. You can also have a date/time automatically
added to the YAML Matter.

Example:
let g:jekyll_post_suffix = "textile"
let g:jekyll_post_published = "false"
let g:jekyll_post_created = "epoch"
let g:jekyll_post_created = "%D %T"

You may also want to add a few mappings to stream line the behavior:
map <Leader>jb :JekyllBuild<CR>
Expand Down
19 changes: 18 additions & 1 deletion plugin/jekyll.vim
Expand Up @@ -27,6 +27,10 @@ if !exists('g:jekyll_post_published')
let g:jekyll_post_published = "true"
endif

if !exists('g:jekyll_post_created')
let g:jekyll_post_created = ""
endif

function s:esctitle(str)
let str = a:str
let str = tolower(str)
Expand Down Expand Up @@ -92,6 +96,12 @@ command! -nargs=0 JekyllList :call JekyllList()

function JekyllPost(title)
let published = g:jekyll_post_published
let created = g:jekyll_post_created
if created == "epoch"
let created = localtime()
elseif created != ""
let created = strftime(created)
endif
let title = a:title
if title == ''
let title = input("Post title: ")
Expand All @@ -100,7 +110,14 @@ function JekyllPost(title)
let file_name = strftime("%Y-%m-%d-") . s:esctitle(title) . "." . g:jekyll_post_suffix
echo "Making that post " . file_name
exe "e " . g:jekyll_path . "/_posts/" . file_name
let err = append(0, ['---', 'layout: post', 'title: "' . title . '"', 'published: ' . published, '---', ''])

let template = ["---", "layout: post", "title: \"" . title . "\"", "published: " . published]
if created != ""
call add(template, "created: " . created)
endif
call extend(template,["---", ""])

let err = append(0, template)
else
call s:error("You must specify a title")
endif
Expand Down

0 comments on commit 1e861d5

Please sign in to comment.