Skip to content
Newer
Older
100644 161 lines (141 sloc) 5.77 KB
091ef1c @dbloete Use Bundler for dependency management
dbloete authored
1 require "rubygems"
8698a27 @imathis Cleaned out public from repository, updated gitignore, added syntax
authored
2 require "bundler/setup"
091ef1c @dbloete Use Bundler for dependency management
dbloete authored
3
eefe29e @imathis now Octopress uses partials
authored
4 port = "4000" # preview project port eg. http://localhost:4000
e4c2d57 @imathis irrisponsibly massive commit
authored
5 site = "public" # compiled site directory
eefe29e @imathis now Octopress uses partials
authored
6 source = "source" # source file directory
7 stash = "_stash" # directory to stash posts for speedy generation
8 posts = "_posts" # directory for blog files
9 post_format = "markdown" # file format for new posts when using the post rake task
399fe77 @imathis updated rakefile to support github user pages, and github project pag…
authored
10
11 ## -- Rsync Deploy config -- ##
cc8985d @imathis fixed a few issues with the rakefile, and updated the readme
authored
12 ssh_user = "user@host.com" # for rsync deployment
13 document_root = "~/document_root/" # for rsync deployment
14 ## ---- ##
15
399fe77 @imathis updated rakefile to support github user pages, and github project pag…
authored
16 ## -- Github Pages deploy config -- ##
54766a0 @imathis updated rakefile to support github pages deployments
authored
17 # Read http://pages.github.com for guidance
e4c2d57 @imathis irrisponsibly massive commit
authored
18 # You can deploy to github pages with `rake push_github` or change the default push task below to :push_github
399fe77 @imathis updated rakefile to support github user pages, and github project pag…
authored
19 # If you're not using this, you can remove it
20 source_branch = "source" # this compiles to your deploy branch
de113ec @imathis changed default github pages deploy branch to master
authored
21 deploy_branch = "master" # For user pages, use "master" for project pages use "gh-pages"
399fe77 @imathis updated rakefile to support github user pages, and github project pag…
authored
22 ## ---- ##
54766a0 @imathis updated rakefile to support github pages deployments
authored
23
82d0251 @imathis improved starting point
authored
24 def ok_failed(condition)
25 if (condition)
26 puts "OK"
27 else
28 puts "FAILED"
29 end
30 end
31
d8b796a @imathis Another massive commit:
authored
32 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]"
33 task :install, :theme do |t, args|
34 # copy theme into working Jekyll directories
35 theme = args.theme || 'classic'
36 puts "## Copying "+theme+" theme to Jekyll paths"
37 system "cp -R themes/"+theme+"/source source"
38 system "cp -R themes/"+theme+"/sass sass"
39 system "cp -R themes/"+theme+"/_plugins/ _plugins/"
40
41 # The directories source and sass are ignored for development, but when Octopress is installed
42 # Users must be able to commit these directories, so this removes those lines from the gitignore
43 puts "## Cleaning up..."
44 new_content = ""
45 File.read('.gitignore').each_line do |e|
46 new_content << e unless e.strip == 'source' || e.strip == 'sass'
47 end
48 File.open('.gitignore', 'w') do |io|
49 io << new_content
50 end
51 end
52
e4c2d57 @imathis irrisponsibly massive commit
authored
53 ## if you're deploying with github, change the default deploy to push_github
54 desc "default push task"
55 task :push => [:push_rsync] do
eefe29e @imathis now Octopress uses partials
authored
56 end
57
58 desc "Generate and deploy task"
d8b796a @imathis Another massive commit:
authored
59 task :deploy => [:integrate, :generate, :push] do
af719fb @imathis fixed default deploy task
authored
60 end
61
d8b796a @imathis Another massive commit:
authored
62 desc "Generate jekyll site"
63 task :generate do
64 puts "## Generating Site with Jekyll"
65 system "jekyll"
145f810 @imathis updated rake file, reorganized stylesheets, added google site search,…
authored
66 end
67
a6262dc @imathis added a rake task for creating a new post
authored
68 # usage rake post[my-new-post] or rake post['my new post'] or rake post (defaults to "new-post")
69 desc "Begin a new post in #{source}/_posts"
70 task :post, :filename do |t, args|
e4c2d57 @imathis irrisponsibly massive commit
authored
71 require './_plugins/titlecase.rb'
a6262dc @imathis added a rake task for creating a new post
authored
72 args.with_defaults(:filename => 'new-post')
e4c2d57 @imathis irrisponsibly massive commit
authored
73 open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d')}-#{args.filename.downcase.gsub(/[ _]/, '-')}.#{post_format}", 'w') do |post|
a6262dc @imathis added a rake task for creating a new post
authored
74 post.puts "---"
75 post.puts "title: \"#{args.filename.gsub(/[-_]/, ' ').titlecase}\""
e4c2d57 @imathis irrisponsibly massive commit
authored
76 post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
77 post.puts "layout: post"
a6262dc @imathis added a rake task for creating a new post
authored
78 post.puts "---"
79 end
80 end
81
2f41517 @rwdaigle Update to rakefile to allow working on a single post at a time (and s…
rwdaigle authored
82 # usage rake isolate[my-post]
83 desc "Move all other posts than the one currently being worked on to a temporary stash location (stash) so regenerating the site happens much quicker."
84 task :isolate, :filename do |t, args|
85 stash_dir = "#{source}/#{stash}"
86 FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
87 Dir.glob("#{source}/#{posts}/*.*") do |post|
88 FileUtils.mv post, stash_dir unless post.include?(args.filename)
89 end
90 end
91
92 desc "Move all stashed posts back into the posts directory, ready for site generation."
93 task :integrate do
94 FileUtils.mv Dir.glob("#{source}/#{stash}/*.*"), "#{source}/#{posts}/"
95 end
96
82d0251 @imathis improved starting point
authored
97 desc "list tasks"
145f810 @imathis updated rake file, reorganized stylesheets, added google site search,…
authored
98 task :list do
6c9f156 @imathis updated rakefile, added some basic twitter files
authored
99 puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).to_sentence}"
82d0251 @imathis improved starting point
authored
100 puts "(type rake -T for more detail)\n\n"
101 end
102
dafeb04 @imathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and…
authored
103 desc "Watch the site and regenerate when it changes"
104 task :watch do
8698a27 @imathis Cleaned out public from repository, updated gitignore, added syntax
authored
105 system "trap 'kill $jekyllPid $guardPid $compassPid' Exit; jekyll --auto & jekyllPid=$!; compass watch & compassPid=$!; guard & guardPid=$!; wait"
dafeb04 @imathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and…
authored
106 end
107
399fe77 @imathis updated rakefile to support github user pages, and github project pag…
authored
108 desc "generate and deploy website via rsync"
e4c2d57 @imathis irrisponsibly massive commit
authored
109 multitask :push_rsync do
d8b796a @imathis Another massive commit:
authored
110 puts "## Deploying website via Rsync"
e0a0d09 @imathis paramaterized feed, rsync deployment, and unified layouts
authored
111 ok_failed system("rsync -avz --delete #{site}/ #{ssh_user}:#{document_root}")
82d0251 @imathis improved starting point
authored
112 end
113
e4c2d57 @imathis irrisponsibly massive commit
authored
114 desc "deploy website to github user pages"
115 multitask :push_github do
d8b796a @imathis Another massive commit:
authored
116 puts "## Deploying #{deploy_branch} branch to Github Pages "
54766a0 @imathis updated rakefile to support github pages deployments
authored
117 require 'git'
118 repo = Git.open('.')
d8b796a @imathis Another massive commit:
authored
119 puts "\n## Checking out #{deploy_branch} branch \n"
3a69742 @imathis fixed source_branch variable name in github deploy script
authored
120 repo.branch("#{deploy_branch}").checkout
e4c2d57 @imathis irrisponsibly massive commit
authored
121 (Dir["*"] - ["#{site}"]).each { |f| rm_rf(f) }
54766a0 @imathis updated rakefile to support github pages deployments
authored
122 Dir["#{site}/*"].each {|f| mv(f, ".")}
e4c2d57 @imathis irrisponsibly massive commit
authored
123 rm_rf("#{site}")
d8b796a @imathis Another massive commit:
authored
124 puts "\n## Moving generated /#{site} files \n"
54766a0 @imathis updated rakefile to support github pages deployments
authored
125 Dir["**/*"].each {|f| repo.add(f) }
126 repo.status.deleted.each {|f, s| repo.remove(f)}
d8b796a @imathis Another massive commit:
authored
127 puts "\n## Commiting: Site updated at #{Time.now.utc} \n"
54766a0 @imathis updated rakefile to support github pages deployments
authored
128 message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
129 repo.commit(message)
d8b796a @imathis Another massive commit:
authored
130 puts "\n## Pushing generated /#{site} files to #{deploy_branch} branch\n"
eff018e @imathis trying one more thing with the rake task auto push
authored
131 repo.push
d8b796a @imathis Another massive commit:
authored
132 puts "\n## Github Pages deploy complete\n"
399fe77 @imathis updated rakefile to support github user pages, and github project pag…
authored
133 repo.branch("#{source_branch}").checkout
54766a0 @imathis updated rakefile to support github pages deployments
authored
134 end
135
e4c2d57 @imathis irrisponsibly massive commit
authored
136 desc "start up a web server on the output files"
137 task :start_server => :stop_server do
d8b796a @imathis Another massive commit:
authored
138 print "## Starting serve..."
e4c2d57 @imathis irrisponsibly massive commit
authored
139 system("serve #{site} #{port} > /dev/null 2>&1 &")
140 sleep 1
141 pid = `ps auxw | awk '/bin\\/serve #{site} #{port}/ { print $2 }'`.strip
142 ok_failed !pid.empty?
143 system "open http://localhost:#{port}" unless pid.empty?
82d0251 @imathis improved starting point
authored
144 end
145
e4c2d57 @imathis irrisponsibly massive commit
authored
146 desc "stop the web server"
147 task :stop_server do
148 pid = `ps auxw | awk '/bin\\/serve #{site} #{port}/ { print $2 }'`.strip
82d0251 @imathis improved starting point
authored
149 if pid.empty?
d8b796a @imathis Another massive commit:
authored
150 puts "## Adsf is not running"
82d0251 @imathis improved starting point
authored
151 else
d8b796a @imathis Another massive commit:
authored
152 print "## Stoping adsf..."
82d0251 @imathis improved starting point
authored
153 ok_failed system("kill -9 #{pid}")
154 end
155 end
156
157 desc "preview the site in a web browser"
e4c2d57 @imathis irrisponsibly massive commit
authored
158 task :preview do
159 system "trap 'kill $servePid $jekyllPid $guardPid' Exit; serve #{site} #{port} > /dev/null 2>&1 & servePid=$!; jekyll --auto & jekyllPid=$!; guard & guardPid=$!; compass compile; open http://localhost:#{port}; wait"
9bd7133 @gisikw Fixed 'rake preview on fails vanilla install' bug
gisikw authored
160 end
Something went wrong with that request. Please try again.