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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
| diff --git a/Rakefile b/Rakefile
index dc36850..36f5ee3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -27,6 +27,7 @@ new_post_ext = "md" # default new post file extension when using the n
new_page_ext = "md" # default new page file extension when using the new_page task
server_port = "4000" # port for preview server eg. localhost:4000
+full_stash_dir = "#{source_dir}/#{stash_dir}" # full path for stash dir
desc "Initial setup for Octopress: copies the default theme into the path of Jekyll's generator. Rake install defaults to rake install[classic] to install a different theme run rake install[some_theme_name]"
task :install, :theme do |t, args|
@@ -56,6 +57,21 @@ task :generate do
system "jekyll"
end
+# usage rake generate_only[my-post]
+desc "Generate only the specified post (much faster)"
+task :generate_only, :filename do |t, args|
+ if args.filename
+ filename = args.filename
+ else
+ filename = get_stdin("Enter a post file name: ")
+ end
+ puts "## Stashing other posts"
+ Rake::Task["isolate"].invoke(filename)
+ Rake::Task["generate"].execute
+ puts "## Restoring stashed posts"
+ Rake::Task["integrate"].execute
+end
+
desc "Watch the site and regenerate when it changes"
task :watch do
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
@@ -72,6 +88,34 @@ task :watch do
[jekyllPid, compassPid].each { |pid| Process.wait(pid) }
end
+# usage rake watch_only[my-post]
+desc "watch only the specified post"
+task :watch_only, :filename do |t, args|
+ raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
+
+ if args.filename
+ filename = args.filename
+ else
+ filename = get_stdin("Enter a post file name: ")
+ end
+ puts "## Stashing other posts"
+ Rake::Task["isolate"].invoke(filename)
+
+ puts "Starting to watch source with Jekyll and Compass."
+ system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
+ jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
+ compassPid = Process.spawn("compass watch")
+
+ trap("INT") {
+ [jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
+ puts "## Restoring stashed posts"
+ Rake::Task["integrate"].execute
+ exit 0
+ }
+
+ [jekyllPid, compassPid].each { |pid| Process.wait(pid) }
+end
+
desc "preview the site in a web browser"
task :preview do
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
@@ -89,6 +133,37 @@ task :preview do
[jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
end
+# usage rake preview_only[my-post]
+desc "preview only the specified post"
+task :preview_only, :filename do |t, args|
+ raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
+
+ if args.filename
+ filename = args.filename
+ else
+ filename = get_stdin("Enter a post file name: ")
+ end
+ puts "## Stashing other posts"
+ Rake::Task["isolate"].invoke(filename)
+
+ puts "## Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
+ system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
+ jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
+ compassPid = Process.spawn("compass watch")
+ rackupPid = Process.spawn("rackup --port #{server_port}")
+
+ trap("INT") {
+ [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
+ puts "## Restoring stashed posts"
+ Rake::Task["integrate"].execute
+ exit 0
+ }
+
+ [jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
+
+end
+
+
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
desc "Begin a new post in #{source_dir}/#{posts_dir}"
task :new_post, :title do |t, args|
@@ -193,16 +268,15 @@ end
# usage rake isolate[my-post]
desc "Move all other posts than the one currently being worked on to a temporary stash location (stash) so regenerating the site happens much more quickly."
task :isolate, :filename do |t, args|
- stash_dir = "#{source_dir}/#{stash_dir}"
- FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
+ FileUtils.mkdir(full_stash_dir) unless File.exist?(full_stash_dir)
Dir.glob("#{source_dir}/#{posts_dir}/*.*") do |post|
- FileUtils.mv post, stash_dir unless post.include?(args.filename)
+ FileUtils.mv post, full_stash_dir unless post.include?(args.filename)
end
end
desc "Move all stashed posts back into the posts directory, ready for site generation."
task :integrate do
- FileUtils.mv Dir.glob("#{source_dir}/#{stash_dir}/*.*"), "#{source_dir}/#{posts_dir}/"
+ FileUtils.mv Dir.glob("#{full_stash_dir}/*.*"), "#{source_dir}/#{posts_dir}/"
end
desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache"
|