Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 183 lines (162 sloc) 5.61 kb
82d0251 Brandon Mathis improved starting point
imathis authored
1 require 'active_support'
2
399fe77 Brandon Mathis updated rakefile to support github user pages, and github project pages ...
imathis authored
3 site_url = "http://yoursite.com" # deployed site url for sitemap.xml generator
4 port = "4000" # preview project port eg. http://localhost:4000
5 site = "site" # compiled site directory
6 source = "source" # source file directory
7
8 ## -- Rsync Deploy config -- ##
cc8985d Brandon Mathis fixed a few issues with the rakefile, and updated the readme
imathis authored
9 ssh_user = "user@host.com" # for rsync deployment
10 document_root = "~/document_root/" # for rsync deployment
11 ## ---- ##
12
399fe77 Brandon Mathis updated rakefile to support github user pages, and github project pages ...
imathis authored
13 ## -- Github Pages deploy config -- ##
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
14 # Read http://pages.github.com for guidance
399fe77 Brandon Mathis updated rakefile to support github user pages, and github project pages ...
imathis authored
15 # If you're not using this, you can remove it
16 source_branch = "source" # this compiles to your deploy branch
17 deploy_branch = "gh-pages" # For user pages, use "master" for project pages use "gh-pages"
18 ## ---- ##
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
19
82d0251 Brandon Mathis improved starting point
imathis authored
20 def ok_failed(condition)
21 if (condition)
22 puts "OK"
23 else
24 puts "FAILED"
25 end
26 end
27
af719fb Brandon Mathis fixed default deploy task
imathis authored
28 ## if you're deploying with github, change the default deploy to deploy_github
29 desc "default deploy task"
30 task :deploy => :deploy_rsync do
31 end
32
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
33 desc "generate website in output directory"
34 task :default => [:generate_site, :generate_style] do
24c5fed Brandon Mathis udpated thirdparty integration, it is now conditionally added, updated r...
imathis authored
35 puts ">>> Site Generating Complete! <<<\n\n"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
36 end
37
82d0251 Brandon Mathis improved starting point
imathis authored
38 desc "list tasks"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
39 task :list do
6c9f156 Brandon Mathis updated rakefile, added some basic twitter files
imathis authored
40 puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).to_sentence}"
82d0251 Brandon Mathis improved starting point
imathis authored
41 puts "(type rake -T for more detail)\n\n"
42 end
43
44 desc "remove files in output directory"
45 task :clean do
6c9f156 Brandon Mathis updated rakefile, added some basic twitter files
imathis authored
46 puts ">>> Removing output <<<"
82d0251 Brandon Mathis improved starting point
imathis authored
47 Dir["#{site}/*"].each { |f| rm_rf(f) }
48 end
49
cc8985d Brandon Mathis fixed a few issues with the rakefile, and updated the readme
imathis authored
50 task :clean_debug do
6c9f156 Brandon Mathis updated rakefile, added some basic twitter files
imathis authored
51 puts ">>> Removing debug pages <<<"
3e69c6b Brandon Mathis fixed the deploy rake task so it will delete the debug pages
imathis authored
52 Dir["#{site}/test"].each { |f| rm_rf(f) }
cc8985d Brandon Mathis fixed a few issues with the rakefile, and updated the readme
imathis authored
53 end
54
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
55 desc "Generate styles only"
56 task :generate_style do
6c9f156 Brandon Mathis updated rakefile, added some basic twitter files
imathis authored
57 puts ">>> Generating styles <<<"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
58 system "compass"
59 end
60
61 desc "Generate site files only"
416667c Brandon Mathis added disqus comment support
imathis authored
62 task :generate_site => [:clean, :generate_style] do
24c5fed Brandon Mathis udpated thirdparty integration, it is now conditionally added, updated r...
imathis authored
63 puts "\n\n>>> Generating site files <<<"
c63ccc9 Brandon Mathis updated rakefile to generate pygments syntax highlighting
imathis authored
64 system "jekyll --pygments"
d8d5171 Brandon Mathis added compass, added some basic stylesheets
imathis authored
65 system "mv #{site}/atom.html #{site}/atom.xml"
82d0251 Brandon Mathis improved starting point
imathis authored
66 end
67
dafeb04 Brandon Mathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and mo...
imathis authored
68 def rebuild_site(relative)
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
69 puts "\n\n>>> Change Detected to: #{relative} <<<"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
70 IO.popen('rake generate_site'){|io| print(io.readpartial(512)) until io.eof?}
71 puts '>>> Update Complete <<<'
72 end
73
74 def rebuild_style(relative)
24c5fed Brandon Mathis udpated thirdparty integration, it is now conditionally added, updated r...
imathis authored
75 puts "\n\n>>> Change Detected to: #{relative} <<<"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
76 IO.popen('rake generate_style'){|io| print(io.readpartial(512)) until io.eof?}
dafeb04 Brandon Mathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and mo...
imathis authored
77 puts '>>> Update Complete <<<'
78 end
79
80 desc "Watch the site and regenerate when it changes"
81 task :watch do
82 require 'fssm'
83 puts ">>> Watching for Changes <<<"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
84 FSSM.monitor do
85 path "#{File.dirname(__FILE__)}/#{source}" do
86 update {|base, relative| rebuild_site(relative)}
87 delete {|base, relative| rebuild_site(relative)}
88 create {|base, relative| rebuild_site(relative)}
89 end
6c9f156 Brandon Mathis updated rakefile, added some basic twitter files
imathis authored
90 path "#{File.dirname(__FILE__)}/stylesheets" do
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
91 glob '**/*.sass'
92 update {|base, relative| rebuild_style(relative)}
93 delete {|base, relative| rebuild_style(relative)}
94 create {|base, relative| rebuild_style(relative)}
95 end
dafeb04 Brandon Mathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and mo...
imathis authored
96 end
97 end
98
399fe77 Brandon Mathis updated rakefile to support github user pages, and github project pages ...
imathis authored
99 desc "generate and deploy website via rsync"
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
100 multitask :deploy_rsync => [:default, :clean_debug] do
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
101 puts ">>> Deploying website to #{site_url} <<<"
e0a0d09 Brandon Mathis paramaterized feed, rsync deployment, and unified layouts
imathis authored
102 ok_failed system("rsync -avz --delete #{site}/ #{ssh_user}:#{document_root}")
82d0251 Brandon Mathis improved starting point
imathis authored
103 end
104
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
105 desc "generate and deploy website to github user pages"
34e2555 Brandon Mathis renamed rake task for github deploy
imathis authored
106 multitask :deploy_github => [:default, :clean_debug] do
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
107 puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
108 require 'git'
109 repo = Git.open('.')
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
110 puts "\n>>> Checking out #{deploy_branch} branch <<<\n"
3a69742 Brandon Mathis fixed source_branch variable name in github deploy script
imathis authored
111 repo.branch("#{deploy_branch}").checkout
24246ea Brandon Mathis fixed variables for github in rakefile
imathis authored
112 (Dir["*"] - [site]).each { |f| rm_rf(f) }
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
113 Dir["#{site}/*"].each {|f| mv(f, ".")}
24246ea Brandon Mathis fixed variables for github in rakefile
imathis authored
114 rm_rf(site)
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
115 puts "\n>>> Moving generated site files <<<\n"
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
116 Dir["**/*"].each {|f| repo.add(f) }
117 repo.status.deleted.each {|f, s| repo.remove(f)}
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
118 puts "\n>>> Commiting: Site updated at #{Time.now.utc} <<<\n"
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
119 message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
120 repo.commit(message)
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
121 puts "\n>>> Pushing generated site to #{deploy_branch} branch <<<\n"
eff018e Brandon Mathis trying one more thing with the rake task auto push
imathis authored
122 repo.push
b12b037 Brandon Mathis improved rake file feedback during deploy
imathis authored
123 puts "\n>>> Github Pages deploy complete <<<\n"
399fe77 Brandon Mathis updated rakefile to support github user pages, and github project pages ...
imathis authored
124 repo.branch("#{source_branch}").checkout
54766a0 Brandon Mathis updated rakefile to support github pages deployments
imathis authored
125 end
126
82d0251 Brandon Mathis improved starting point
imathis authored
127 desc "start up an instance of serve on the output files"
128 task :start_serve => :stop_serve do
129 cd "#{site}" do
130 print "Starting serve..."
131 ok_failed system("serve #{port} > /dev/null 2>&1 &")
132 end
133 end
134
135 desc "stop all instances of serve"
136 task :stop_serve do
137 pid = `ps auxw | awk '/bin\\/serve\\ #{port}/ { print $2 }'`.strip
138 if pid.empty?
139 puts "Serve is not running"
140 else
141 print "Stoping serve..."
142 ok_failed system("kill -9 #{pid}")
143 end
144 end
145
146 desc "preview the site in a web browser"
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
147 multitask :preview => [:default, :start_serve] do
82d0251 Brandon Mathis improved starting point
imathis authored
148 system "open http://localhost:#{port}"
dafeb04 Brandon Mathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and mo...
imathis authored
149 end
150
151
152 desc "Build an XML sitemap of all html files."
145f810 Brandon Mathis updated rake file, reorganized stylesheets, added google site search, ad...
imathis authored
153 task :sitemap => :default do
dafeb04 Brandon Mathis updated rakefile to use FSSM in `rake watch`, generate a sitemap, and mo...
imathis authored
154 html_files = FileList.new("#{site}/**/*.html").map{|f| f[("#{site}".size)..-1]}.map do |f|
155 if f.ends_with?("index.html")
156 f[0..(-("index.html".size + 1))]
157 else
158 f
159 end
160 end.sort_by{|f| f.size}
161 open("#{site}/sitemap.xml", 'w') do |sitemap|
162 sitemap.puts %Q{<?xml version="1.0" encoding="UTF-8"?>}
163 sitemap.puts %Q{<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">}
164 html_files.each do |f|
165 priority = case f
166 when %r{^/$}
167 1.0
168 when %r{^/blog}
169 0.9
170 else
171 0.8
172 end
173 sitemap.puts %Q{ <url>}
174 sitemap.puts %Q{ <loc>#{site_url}#{f}</loc>}
175 sitemap.puts %Q{ <lastmod>#{Time.to_s('%Y-%m-%d')}</lastmod>}
176 sitemap.puts %Q{ <changefreq>weekly</changefreq>}
177 sitemap.puts %Q{ <priority>#{priority}</priority>}
178 sitemap.puts %Q{ </url>}
179 end
180 sitemap.puts %Q{</urlset>}
181 puts "Created #{site}/sitemap.xml"
182 end
82d0251 Brandon Mathis improved starting point
imathis authored
183 end
Something went wrong with that request. Please try again.