-
Notifications
You must be signed in to change notification settings - Fork 0
/
jekyll.thor
51 lines (44 loc) · 1.35 KB
/
jekyll.thor
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "stringex"
class Jekyll < Thor
package_name "Jekyll"
desc "new_post", "create a new post"
method_option :editor, :default => "nvim"
method_option :category, :default => "random"
method_option :tags, :default => "random"
def new_post(*title)
title = title.join(" ")
date = Time.now.strftime('%Y-%m-%d')
filename = "_posts/#{date}-#{title.to_url}.md"
if File.exist?(filename)
abort("#{filename} already exists!")
end
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "category: #{options[:category]}"
post.puts "tag: [#{options[:tags]}]"
post.puts "---"
end
system(options[:editor], filename)
end
desc "new_tab", "create a new tab"
method_option :editor, :default => "nvim"
method_option :order, :default => 5
def new_tab(*title)
title = title.join(" ")
filename = "_tabs/#{title.to_url}.md"
if File.exist?(filename)
abort("#{filename} already exists!")
end
puts "Creating new tab: #{filename}"
open(filename, 'w') do |tab|
tab.puts "---"
tab.puts "title: \"#{title.gsub(/&/,'&')}\""
tab.puts "order: #{options[:order]}"
tab.puts "---"
end
system(options[:editor], filename)
end
end