-
Notifications
You must be signed in to change notification settings - Fork 31
/
Rakefile
73 lines (62 loc) · 2.34 KB
/
Rakefile
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'stringex'
require 'highline/import'
desc "Create a new post"
task :new_post, :title do |t, args|
mkdir_p './content/blog'
args.with_defaults(:title => 'New Blog Post')
title = args.title.capitalize
if title.include?('"')
title = title.gsub('"', '\"')
end
dirname = "./content/blog/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}" # include datestamp in title
# dirname = "./content/blog/#{url_title}" # A default name without datestamp
filename = "#{dirname}/index.md"
if Dir.exists?(dirname)
abort('rake aborted! Directory name already exists.') if ask("#{dirname} already exists. Want to overwrite? y, n", ['y', 'n']) == 'n'
end
mkdir_p dirname
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts '---'
post.puts "title: \"#{title}\""
post.puts "author: # Optional"
post.puts "subtitle: # Optional"
post.puts "created_at: #{Time.now}"
post.puts 'kind: article'
post.puts "header_class: # Default defined in blog layout"
post.puts "header_image: # Optional. If image specified, header_class automatically assigned, else default"
post.puts "---\n\n"
end
# Autogenerating was causing a permissions issue, so chown all blog files to belong to user
stat = File.stat('.git')
sh "chown -Rf #{stat.uid}:#{stat.gid} content/blog"
end
desc "Create a new robot"
task :new_robot, :title do |t, args|
mkdir_p './content/robots'
args.with_defaults(:title => 'New Robot')
title = args.title
dirname = "./content/robots/#{title}"
filename = "#{dirname}/index.md"
if Dir.exists?(dirname)
abort('rake aborted! Directory name already exists.') if ask("#{dirname} already exists. Want to overwrite? y, n", ['y', 'n']) == 'n'
end
mkdir_p dirname
puts "Creating new robot: #{filename}"
open(filename, 'w') do |post|
post.puts '---'
post.puts "featured: false"
post.puts "title: \"#{title}\""
post.puts "image:"
post.puts "header_image:"
post.puts "subtitle:"
post.puts "summary:"
post.puts "categories: # e.g. - manipulator"
post.puts "tags: # e.g. - android"
post.puts "features: # e.g. - 100kg payload"
post.puts "---\n\n"
end
# Autogenerating was causing a permissions issue, so chown all robot files to belong to user
stat = File.stat('.git')
sh "chown -Rf #{stat.uid}:#{stat.gid} content/robots"
end