My first Jekyll blog which I hosted on GitHub Pages before they offered SSL http://habdas.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Rakefile 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. require "rubygems"
  2. require "bundler/setup"
  3. require "stringex"
  4. require "fileutils"
  5. ## -- Rsync Deploy config -- ##
  6. # Be sure your public key is listed in your server's ~/.ssh/authorized_keys file
  7. ssh_user = "user@domain.com"
  8. ssh_port = "22"
  9. document_root = "~/website.com/"
  10. rsync_delete = false
  11. rsync_args = "" # Any extra arguments to pass to rsync
  12. deploy_default = "push"
  13. # This will be configured for you when you run config_deploy
  14. deploy_branch = "master"
  15. ## -- Misc Configs -- ##
  16. public_dir = "public" # compiled site directory
  17. source_dir = "source" # source file directory
  18. blog_index_dir = 'source' # directory for your blog's index page (if you put your index in source/blog/index.html, set this to 'source/blog')
  19. deploy_dir = "_deploy" # deploy directory (for Github pages deployment)
  20. stash_dir = "_stash" # directory to stash posts for speedy generation
  21. posts_dir = "_posts" # directory for blog files
  22. themes_dir = ".themes" # directory for blog files
  23. new_post_ext = "md" # default new post file extension when using the new_post task
  24. new_page_ext = "md" # default new page file extension when using the new_page task
  25. server_port = "4000" # port for preview server eg. localhost:4000
  26. asset_version = Time.new.strftime("%y%m%d%H%M") # For asset versioning
  27. 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]"
  28. task :install, :theme do |t, args|
  29. if File.directory?(source_dir) || File.directory?("sass")
  30. abort("rake aborted!") if ask("A theme is already installed, proceeding will overwrite existing files. Are you sure?", ['y', 'n']) == 'n'
  31. end
  32. # copy theme into working Jekyll directories
  33. theme = args.theme || 'classic'
  34. puts "## Copying "+theme+" theme into ./#{source_dir} and ./sass"
  35. mkdir_p source_dir
  36. cp_r "#{themes_dir}/#{theme}/source/.", source_dir
  37. mkdir_p "sass"
  38. cp_r "#{themes_dir}/#{theme}/sass/.", "sass"
  39. mkdir_p "#{source_dir}/#{posts_dir}"
  40. mkdir_p public_dir
  41. end
  42. #######################
  43. # Working with Jekyll #
  44. #######################
  45. desc "Generate jekyll site"
  46. task :generate => [:sass, :update_asset_versions, :jekyll, :combine, :minify]
  47. desc "Process CoffeeScript"
  48. task :coffee do
  49. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  50. puts "## Generating JS with CoffeeScriptRedux"
  51. system "#{ENV['COFFEESCRIPT_HOME']}/bin/coffee --js -i #{source_dir}/javascripts/custom.coffee > #{source_dir}/javascripts/custom_cstest.js"
  52. system "#{ENV['COFFEESCRIPT_HOME']}/bin/coffee --source-map -i #{source_dir}/javascripts/custom.coffee > #{source_dir}/javascripts/custom.js.map"
  53. end
  54. desc "Process Sass"
  55. task :sass do
  56. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  57. puts "## Generating CSS with Compass"
  58. system "compass compile --css-dir #{source_dir}/stylesheets"
  59. end
  60. desc "Run Jekyll"
  61. task :jekyll do
  62. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  63. puts "## Generating Site with Jekyll"
  64. system "jekyll"
  65. end
  66. desc "Combine CSS"
  67. task :combine_css do
  68. puts "## Combining CSS"
  69. styles_dir = "#{source_dir}/stylesheets"
  70. system "cat #{styles_dir}/screen.css #{styles_dir}/jquery.fancybox.css > #{styles_dir}/all.css"
  71. end
  72. desc "Combine JS"
  73. task :combine_js do
  74. puts "## Combining JS"
  75. scripts_dir = "#{source_dir}/javascripts"
  76. system "cat #{scripts_dir}/libs/jquery.min.js #{scripts_dir}/modernizr-2.0.js #{scripts_dir}/octopress.js #{scripts_dir}/github.js #{scripts_dir}/jquery.fancybox.js > #{scripts_dir}/all.js"
  77. end
  78. desc "Combine CSS/JS"
  79. task :combine => [:combine_css, :combine_js]
  80. desc "Minify CSS"
  81. task :minify_css do
  82. puts "## Minifying CSS"
  83. input = "#{source_dir}/stylesheets/all.css"
  84. output = "#{source_dir}/_includes/inline.css"
  85. system "cleancss -e -o #{output} #{input}"
  86. end
  87. desc "Minify JS"
  88. task :minify_js do
  89. puts "## Minifying JS"
  90. input = "#{source_dir}/javascripts/all.js"
  91. output = "#{source_dir}/javascripts/all.#{asset_version}.js"
  92. source_map_option = "--source-map #{source_dir}/javascripts/all.#{asset_version}.js.map"
  93. source_map_root_option = "--source-map-root http://www.habdas.org"
  94. system "uglifyjs #{input} -o #{output} #{source_map_option} #{source_map_root_option} -p 2 -m -c warnings=false"
  95. Dir.glob("#{source_dir}/javascripts/all.*").each do |f|
  96. FileUtils.mv(f, "#{public_dir}/javascripts")
  97. end
  98. end
  99. desc "Minify CSS/JS"
  100. task :minify => [:minify_css, :minify_js]
  101. desc "Optimize Images"
  102. task :optimize_images do
  103. puts "## Optimizing Images"
  104. Dir.glob("#{source_dir}/images/*.{jp,pn}g").each do |f|
  105. ext = File.extname(f)
  106. optimized_file = "#{File.basename(f, ext)}-optimized#{ext}"
  107. if test(?f, f) and not File.exists?(optimized_file)
  108. ok_failed system("imagemin #{f} > #{source_dir}/images/#{optimized_file}")
  109. end
  110. end
  111. end
  112. # Experimental WebP image optimizer
  113. # desc "Optimize Images"
  114. # task :optimize_images do
  115. # puts "## Optimizing Images"
  116. # Dir.glob("#{source_dir}/images/*.{jp,pn}g").each do |f|
  117. # webp_file = "#{f[0..-4]}webp"
  118. # puts "Checking #{f} -> #{webp_file}"
  119. # if test(?f, f) and not File.exists?(webp_file)
  120. # ok_failed system("cwebp -q 100 #{f} -o #{webp_file}")
  121. # end
  122. # end
  123. # end
  124. desc "GZip HTML"
  125. task :gzip_html do
  126. puts "## GZipping HTML"
  127. system 'find public/ -type f -name \*.html -exec gzip -9 {} \;'
  128. # Batch rename .html.gz to .html
  129. Dir['**/*.html.gz'].each do |f|
  130. test(?f, f) and File.rename(f, f.gsub(/\.html\.gz/, '.html'))
  131. end
  132. end
  133. desc "GZip CSS"
  134. task :gzip_css do
  135. puts "## GZipping CSS"
  136. styles_dir = "#{public_dir}/stylesheets"
  137. system "gzip -9 #{styles_dir}/all.#{asset_version}.css"
  138. system "mv #{styles_dir}/all.#{asset_version}.css{.gz,}"
  139. end
  140. desc "GZip JS"
  141. task :gzip_js do
  142. puts "## GZipping JS"
  143. scripts_dir = "#{public_dir}/javascripts"
  144. system "gzip -9 #{scripts_dir}/all.#{asset_version}.js"
  145. system "mv #{scripts_dir}/all.#{asset_version}.js{.gz,}"
  146. end
  147. desc "GZip All"
  148. task :gzip => [:gzip_html, :gzip_css, :gzip_js]
  149. desc "Update head include for static assets"
  150. task :update_asset_versions do
  151. puts "## Updating asset versions"
  152. # Replace instances of all.js and all.1234.js with all.{version}.js
  153. content = ''
  154. File.open("#{source_dir}/_includes/head.html", 'r') do |file|
  155. content = file.read.gsub(/all(\.\d+)?\./, "all.#{asset_version}.")
  156. end
  157. File.open("#{source_dir}/_includes/head.html", 'w') do |file|
  158. file.write(content)
  159. end
  160. content = ''
  161. File.open("#{source_dir}/_includes/after_footer.html", 'r') do |file|
  162. content = file.read.gsub(/all(\.\d+)?\./, "all.#{asset_version}.")
  163. end
  164. File.open("#{source_dir}/_includes/after_footer.html", 'w') do |file|
  165. file.write(content)
  166. end
  167. end
  168. desc "Watch the site and regenerate when it changes"
  169. task :watch do
  170. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  171. puts "Starting to watch source with Jekyll and Compass."
  172. system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
  173. jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
  174. compassPid = Process.spawn("compass watch")
  175. trap("INT") {
  176. [jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
  177. exit 0
  178. }
  179. [jekyllPid, compassPid].each { |pid| Process.wait(pid) }
  180. end
  181. desc "preview the site in a web browser"
  182. task :preview do
  183. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  184. puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
  185. system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
  186. # Replace instances of all.{version}.js with all.js
  187. content = ''
  188. File.open("#{source_dir}/_includes/head.html", 'r') do |file|
  189. content = file.read.gsub(/all(\.\d+)?\./, "all.")
  190. end
  191. File.open("#{source_dir}/_includes/head.html", 'w') do |file|
  192. file.write(content)
  193. end
  194. jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
  195. compassPid = Process.spawn("compass watch")
  196. rackupPid = Process.spawn("rackup --port #{server_port}")
  197. trap("INT") {
  198. [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
  199. exit 0
  200. }
  201. [jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
  202. end
  203. # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
  204. desc "Begin a new post in #{source_dir}/#{posts_dir}"
  205. task :new_post, :title do |t, args|
  206. if args.title
  207. title = args.title
  208. else
  209. title = get_stdin("Enter a title for your post: ")
  210. end
  211. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  212. mkdir_p "#{source_dir}/#{posts_dir}"
  213. filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
  214. if File.exist?(filename)
  215. abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
  216. end
  217. puts "Creating new post: #{filename}"
  218. open(filename, 'w') do |post|
  219. post.puts "---"
  220. post.puts "layout: post"
  221. post.puts "title: \"#{title.gsub(/&/,'&')}\""
  222. post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
  223. post.puts "comments: true"
  224. post.puts "categories: "
  225. post.puts "---"
  226. end
  227. end
  228. # usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown")
  229. desc "Create a new page in #{source_dir}/(filename)/index.#{new_page_ext}"
  230. task :new_page, :filename do |t, args|
  231. raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  232. args.with_defaults(:filename => 'new-page')
  233. page_dir = [source_dir]
  234. if args.filename.downcase =~ /(^.+\/)?(.+)/
  235. filename, dot, extension = $2.rpartition('.').reject(&:empty?) # Get filename and extension
  236. title = filename
  237. page_dir.concat($1.downcase.sub(/^\//, '').split('/')) unless $1.nil? # Add path to page_dir Array
  238. if extension.nil?
  239. page_dir << filename
  240. filename = "index"
  241. end
  242. extension ||= new_page_ext
  243. page_dir = page_dir.map! { |d| d = d.to_url }.join('/') # Sanitize path
  244. filename = filename.downcase.to_url
  245. mkdir_p page_dir
  246. file = "#{page_dir}/#{filename}.#{extension}"
  247. if File.exist?(file)
  248. abort("rake aborted!") if ask("#{file} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
  249. end
  250. puts "Creating new page: #{file}"
  251. open(file, 'w') do |page|
  252. page.puts "---"
  253. page.puts "layout: page"
  254. page.puts "title: \"#{title}\""
  255. page.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
  256. page.puts "comments: true"
  257. page.puts "sharing: true"
  258. page.puts "footer: true"
  259. page.puts "---"
  260. end
  261. else
  262. puts "Syntax error: #{args.filename} contains unsupported characters"
  263. end
  264. end
  265. # usage rake isolate[my-post]
  266. 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."
  267. task :isolate, :filename do |t, args|
  268. stash_dir = "#{source_dir}/#{stash_dir}"
  269. FileUtils.mkdir(stash_dir) unless File.exist?(stash_dir)
  270. Dir.glob("#{source_dir}/#{posts_dir}/*.*") do |post|
  271. FileUtils.mv post, stash_dir unless post.include?(args.filename)
  272. end
  273. end
  274. desc "Move all stashed posts back into the posts directory, ready for site generation."
  275. task :integrate do
  276. FileUtils.mv Dir.glob("#{source_dir}/#{stash_dir}/*.*"), "#{source_dir}/#{posts_dir}/"
  277. end
  278. desc "Clean out caches: .pygments-cache, .gist-cache, .sass-cache, .flickr-cache"
  279. task :clean do
  280. rm_rf [".pygments-cache/**", ".gist-cache/**", ".sass-cache/**", "source/stylesheets/screen.css", ".flickr-cache/**"]
  281. end
  282. desc "Move sass to sass.old, install sass theme updates, replace sass/custom with sass.old/custom"
  283. task :update_style, :theme do |t, args|
  284. theme = args.theme || 'classic'
  285. if File.directory?("sass.old")
  286. puts "removed existing sass.old directory"
  287. rm_r "sass.old", :secure=>true
  288. end
  289. mv "sass", "sass.old"
  290. puts "## Moved styles into sass.old/"
  291. cp_r "#{themes_dir}/"+theme+"/sass/", "sass"
  292. cp_r "sass.old/custom/.", "sass/custom"
  293. puts "## Updated Sass ##"
  294. end
  295. desc "Move source to source.old, install source theme updates, replace source/_includes/navigation.html with source.old's navigation"
  296. task :update_source, :theme do |t, args|
  297. theme = args.theme || 'classic'
  298. if File.directory?("#{source_dir}.old")
  299. puts "## Removed existing #{source_dir}.old directory"
  300. rm_r "#{source_dir}.old", :secure=>true
  301. end
  302. mkdir "#{source_dir}.old"
  303. cp_r "#{source_dir}/.", "#{source_dir}.old"
  304. puts "## Copied #{source_dir} into #{source_dir}.old/"
  305. cp_r "#{themes_dir}/"+theme+"/source/.", source_dir, :remove_destination=>true
  306. cp_r "#{source_dir}.old/_includes/custom/.", "#{source_dir}/_includes/custom/", :remove_destination=>true
  307. cp "#{source_dir}.old/favicon.png", source_dir
  308. mv "#{source_dir}/index.html", "#{blog_index_dir}", :force=>true if blog_index_dir != source_dir
  309. cp "#{source_dir}.old/index.html", source_dir if blog_index_dir != source_dir && File.exists?("#{source_dir}.old/index.html")
  310. puts "## Updated #{source_dir} ##"
  311. end
  312. ##############
  313. # Deploying #
  314. ##############
  315. desc "Default deploy task"
  316. task :deploy do
  317. # Check if preview posts exist, which should not be published
  318. if File.exists?(".preview-mode")
  319. puts "## Found posts in preview mode, regenerating files ..."
  320. File.delete(".preview-mode")
  321. Rake::Task[:generate].execute
  322. end
  323. Rake::Task[:copydot].invoke(source_dir, public_dir)
  324. Rake::Task["#{deploy_default}"].execute
  325. end
  326. desc "Generate website and deploy"
  327. task :gen_deploy => [:clean, :integrate, :generate, :deploy] do
  328. end
  329. desc "copy dot files for deployment"
  330. task :copydot, :source, :dest do |t, args|
  331. FileList["#{args.source}/**/.*"].exclude("**/.", "**/..", "**/.DS_Store", "**/._*").each do |file|
  332. cp_r file, file.gsub(/#{args.source}/, "#{args.dest}") unless File.directory?(file)
  333. end
  334. end
  335. desc "Deploy website via rsync"
  336. task :rsync do
  337. exclude = ""
  338. if File.exists?('./rsync-exclude')
  339. exclude = "--exclude-from '#{File.expand_path('./rsync-exclude')}'"
  340. end
  341. puts "## Deploying website via Rsync"
  342. ok_failed system("rsync -avze 'ssh -p #{ssh_port}' #{exclude} #{rsync_args} #{"--delete" unless rsync_delete == false} #{public_dir}/ #{ssh_user}:#{document_root}")
  343. end
  344. desc "deploy public directory to github pages"
  345. multitask :push do
  346. puts "## Deploying branch to Github Pages "
  347. puts "## Pulling any updates from Github Pages "
  348. cd "#{deploy_dir}" do
  349. system "git pull"
  350. end
  351. (Dir["#{deploy_dir}/*"]).each { |f| rm_rf(f) }
  352. Rake::Task[:copydot].invoke(public_dir, deploy_dir)
  353. puts "\n## Copying #{public_dir} to #{deploy_dir}"
  354. cp_r "#{public_dir}/.", deploy_dir
  355. cd "#{deploy_dir}" do
  356. system "git add -A"
  357. puts "\n## Commiting: Site updated at #{Time.now.utc}"
  358. message = "Site updated at #{Time.now.utc} [ci skip]"
  359. system "git commit -m \"#{message}\""
  360. puts "\n## Pushing generated #{deploy_dir} website"
  361. # system "git push origin #{deploy_branch}"
  362. system "git push origin #{deploy_branch} --force --quiet" # hide github token
  363. puts "\n## Github Pages deploy complete"
  364. end
  365. end
  366. desc "Update configurations to support publishing to root or sub directory"
  367. task :set_root_dir, :dir do |t, args|
  368. puts ">>> !! Please provide a directory, eg. rake config_dir[publishing/subdirectory]" unless args.dir
  369. if args.dir
  370. if args.dir == "/"
  371. dir = ""
  372. else
  373. dir = "/" + args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, '');
  374. end
  375. rakefile = IO.read(__FILE__)
  376. rakefile.sub!(/public_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "public_dir\\1=\\2\\3public#{dir}\\3")
  377. File.open(__FILE__, 'w') do |f|
  378. f.write rakefile
  379. end
  380. compass_config = IO.read('config.rb')
  381. compass_config.sub!(/http_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_path\\1=\\2\\3#{dir}/\\3")
  382. compass_config.sub!(/http_images_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_images_path\\1=\\2\\3#{dir}/images\\3")
  383. compass_config.sub!(/http_fonts_path(\s*)=(\s*)(["'])[\w\-\/]*["']/, "http_fonts_path\\1=\\2\\3#{dir}/fonts\\3")
  384. compass_config.sub!(/css_dir(\s*)=(\s*)(["'])[\w\-\/]*["']/, "css_dir\\1=\\2\\3public#{dir}/stylesheets\\3")
  385. File.open('config.rb', 'w') do |f|
  386. f.write compass_config
  387. end
  388. jekyll_config = IO.read('_config.yml')
  389. jekyll_config.sub!(/^destination:.+$/, "destination: public#{dir}")
  390. jekyll_config.sub!(/^subscribe_rss:\s*\/.+$/, "subscribe_rss: #{dir}/atom.xml")
  391. jekyll_config.sub!(/^root:.*$/, "root: /#{dir.sub(/^\//, '')}")
  392. File.open('_config.yml', 'w') do |f|
  393. f.write jekyll_config
  394. end
  395. rm_rf public_dir
  396. mkdir_p "#{public_dir}#{dir}"
  397. puts "## Site's root directory is now '/#{dir.sub(/^\//, '')}' ##"
  398. end
  399. end
  400. desc "Set up _deploy folder and deploy branch for Github Pages deployment"
  401. task :setup_github_pages, :repo do |t, args|
  402. if args.repo
  403. repo_url = args.repo
  404. else
  405. puts "Enter the read/write url for your repository"
  406. puts "(For example, 'git@github.com:your_username/your_username.github.io)"
  407. puts " or 'https://github.com/your_username/your_username.github.io')"
  408. repo_url = get_stdin("Repository url: ")
  409. end
  410. protocol = (repo_url.match(/(^git)@/).nil?) ? 'https' : 'git'
  411. if protocol == 'git'
  412. user = repo_url.match(/[\/:]([^\/]+)\/[^\/]+$/)[1]
  413. else
  414. user = repo_url.match(/github\.com\/([^\/]+)/)[1]
  415. end
  416. branch = (repo_url.match(/\/[\w-]+\.github\.(?:io|com)/).nil?) ? 'gh-pages' : 'master'
  417. project = (branch == 'gh-pages') ? repo_url.match(/\/([^\.]+)/)[1] : ''
  418. unless (`git remote -v` =~ /origin.+?octopress(?:\.git)?/).nil?
  419. # If octopress is still the origin remote (from cloning) rename it to octopress
  420. system "git remote rename origin octopress"
  421. if branch == 'master'
  422. # If this is a user/organization pages repository, add the correct origin remote
  423. # and checkout the source branch for committing changes to the blog source.
  424. system "git remote add origin #{repo_url}"
  425. # puts "Added remote #{repo_url} as origin"
  426. puts "Added remote as origin" # don't put repo_url in travis-ci as it may contains token
  427. system "git config branch.master.remote origin"
  428. puts "Set origin as default remote"
  429. system "git branch -m master source"
  430. puts "Master branch renamed to 'source' for committing your blog source files"
  431. else
  432. unless !public_dir.match("#{project}").nil?
  433. system "rake set_root_dir[#{project}]"
  434. end
  435. end
  436. end
  437. jekyll_config = IO.read('_config.yml')
  438. jekyll_config.sub!(/^url:.*$/, "url: #{blog_url(user, project)}")
  439. File.open('_config.yml', 'w') do |f|
  440. f.write jekyll_config
  441. end
  442. rm_rf deploy_dir
  443. mkdir deploy_dir
  444. cd "#{deploy_dir}" do
  445. system "git init"
  446. system "echo 'My Octopress Page is coming soon &hellip;' > index.html"
  447. system "git add ."
  448. system "git commit -m \"Octopress init [ci skip]\""
  449. system "git branch -m gh-pages" unless branch == 'master'
  450. system "git remote add origin #{repo_url}"
  451. rakefile = IO.read(__FILE__)
  452. rakefile.sub!(/deploy_branch(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_branch\\1=\\2\\3#{branch}\\3")
  453. rakefile.sub!(/deploy_default(\s*)=(\s*)(["'])[\w-]*["']/, "deploy_default\\1=\\2\\3push\\3")
  454. File.open(__FILE__, 'w') do |f|
  455. f.write rakefile
  456. end
  457. end
  458. puts "\n---\n## Now you can deploy to #{repo_url} with `rake deploy` ##"
  459. end
  460. def ok_failed(condition)
  461. if (condition)
  462. puts "OK"
  463. else
  464. puts "FAILED"
  465. end
  466. end
  467. def get_stdin(message)
  468. print message
  469. STDIN.gets.chomp
  470. end
  471. def ask(message, valid_options)
  472. if valid_options
  473. answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
  474. else
  475. answer = get_stdin(message)
  476. end
  477. answer
  478. end
  479. def blog_url(user, project)
  480. url = if File.exists?('source/CNAME')
  481. "http://#{IO.read('source/CNAME').strip}"
  482. else
  483. "http://#{user}.github.io"
  484. end
  485. url += "/#{project}" unless project == ''
  486. url
  487. end
  488. desc "list tasks"
  489. task :list do
  490. puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}"
  491. puts "(type rake -T for more detail)\n\n"
  492. end