-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjekyll.thor
More file actions
34 lines (27 loc) · 802 Bytes
/
Copy pathjekyll.thor
File metadata and controls
34 lines (27 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'stringex'
# Taken from:
# http://jonas.brusman.se/2012/12/28/create-jekyll-posts-from-the-command-line/
#
# Usage: thor jekyll:new <title post>
class Jekyll < Thor
desc 'new', 'create a new post'
method_option :editor, default: 'atom'
def new(*title)
title = title.join('')
date = Time.now.strftime('%Y-%m-%d')
filename = "_posts/#{date}-#{title.to_url}.md"
abort("#{filename} already exists!") if File.exist?(filename)
create_post(filename, title)
system(options[:editor], '.')
end
private
def create_post(filename, title)
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts '---'
post.puts 'layout: post'
post.puts "title: \"#{title.gsub(/&/, '&')}\""
post.puts '---'
end
end
end