-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
71 lines (55 loc) · 1.31 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
require "time"
##########
# Config #
##########
# Common
public_dir = "_site" # compiled site directory
posts_dir = "_posts" # directory for blog files
#######################
# Working with Jekyll #
#######################
task :default do
system "rake --tasks"
end
desc "Initial setup"
task :install do |t, args|
system "bundle install"
end
desc "Generate jekyll site"
task :generate do
puts "## Generating site"
system "JEKYLL_ENV=production bundle exec jekyll build"
end
desc "preview the site in a web browser"
task :preview do
puts "## Generate and serve site"
system "bundle exec jekyll serve"
end
# usage `rake new_post` or `rake new_post 'Title for the post'
desc "Create a new post"
task :new_post do |t, args|
date = DateTime.parse(Time.now.to_s).strftime("%Y-%m-%d")
title = get_stdin("Enter the post title: ")
title_slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
file_name = "#{date}-#{title_slug}.md"
file_path = "#{posts_dir}/#{file_name}"
puts "Creating new post at #{file_path}"
content = <<-CONTENT
---
layout: post
title: "#{title}"
date: #{date} 12:00:00 +0100
categories:
---
CONTENT
File.open(file_path, "w+") do |f|
f.write(content)
end
end
#########
# Utils #
#########
def get_stdin(message)
print message
STDIN.gets.chomp
end